Z
Z
Zybastik2015-02-21 13:57:23
Ruby on Rails
Zybastik, 2015-02-21 13:57:23

Ruby file hosting help in finding a bug?

Good day, I’ll say right away that I’m trying to do everything as they described on Habré “Home file hosting based on Sinatra and DataMapper. Part 3 - Very Advanced features” I rewrote everything into a virtual machine. ubuntu server 14. When I run "thin start -C thin.yml" a log file appears with errors

>> Writing PID to /home/administrator/web/tmp/thin.pid
>> Exiting!
/home/administrator/web/config/config.ru:2:in `block in <main>': uninitialized constant Sinatra (NameError)
  from /usr/lib/ruby/vendor_ruby/rack/builder.rb:55:in `instance_eval'
  from /usr/lib/ruby/vendor_ruby/rack/builder.rb:55:in `initialize'
  from /home/administrator/web/config/config.ru:1:in `new'
  from /home/administrator/web/config/config.ru:1:in `<main>'
  from /usr/lib/ruby/vendor_ruby/rack/adapter/loader.rb:36:in `eval'
  from /usr/lib/ruby/vendor_ruby/rack/adapter/loader.rb:36:in `load'
  from /usr/lib/ruby/vendor_ruby/thin/controllers/controller.rb:181:in `load_rackup_config'
  from /usr/lib/ruby/vendor_ruby/thin/controllers/controller.rb:71:in `start'
  from /usr/lib/ruby/vendor_ruby/thin/runner.rb:185:in `run_command'
  from /usr/lib/ruby/vendor_ruby/thin/runner.rb:151:in `run!'
  from /usr/bin/thin:6:in `<main>'

Description of the config.ru file itself
require 'init'
Rack::Handler::Thin.run Sinatra::Application, :Port => 3000, :Host =>"192.168.0.14"

Itself only yesterday began to tell to study ubuntu and all connected.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Viktor Vsk, 2015-02-21
@Zybastik

The error says that it is not connected with the Sinatra gem.
What is in init.rb according to the article is somehow unclear.
You need to paste it somewhere
either in init.rb or in config.ru

Z
Zybasstik, 2015-02-21
@Zybasstik

Thanks, yes you are right. I put it in Config.ru and it seems to have started. The log showed:

>> Writing PID to /home/administrator/web/tmp/thin.pid
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 192.168.0.14:4567, CTRL+C to stop

But when the client tries to connect, an error occurs:
I'm looking at it myself for now... but if anyone has any ideas... glad to hear it.
As a result, I found the list.haml file, I think I need to dig here?
- if @files.empty?
  %h1 Файлов нет.
- else
  .list
    %h1 Список файлов
    %table{ :cellspacing => 0}
      %tr
        %th Файл
        %th Загружен
        %th Скачан
        %th Удалить
      - @files.each do |file|
        %tr
          %td.filename
            %a{ :href => "/#{file.sha}/#{file.id}?nowait=true", :title => file.filename }= file.filename
            = "(#{file.filesize/1024} Kb)"
            %a{ :href => "/#{file.sha}/#{file.id}" } Для пересылки 
          %td.created_at= file.created_at.strftime("%d %b")
          %td.downloads= file.downloads
          %td.delete
            %a{ :href => "/#{file.sha}/#{file.id}/delete", :title => "Удалить", :onclick => "return ORLY();" } Удалить
.upload
  %h1 Добавить
  %form{ :name => "new_file", :enctype => "multipart/form-data", :method => "post", :action => "/" }
    %input{ :name => "file", :type => "file" }
    %br
    %input{ :type => "submit", :value => "Закачать" }

#init.rb
require 'rubygems'
require 'logger'
require 'ftools'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require File.expand_path(File.dirname(__FILE__) + '/lib/stored_file')
require File.expand_path(File.dirname(__FILE__) + '/lib/sinatra/lib/sinatra')
require File.expand_path(File.dirname(__FILE__) + '/config/config')
require File.expand_path(File.dirname(__FILE__) + '/lib/authorization')

helpers do
  include Sinatra::Authorization
end

get '/' do
  require_administrative_privileges
  @files = StoredFile.all
  haml :list
end

post '/' do
  require_administrative_privileges
  tempfile = params['file'][:tempfile]
  filename = params['file'][:filename]
  digest = Digest::SHA1.hexdigest(filename)
  @file = StoredFile.create :filename => filename, :sha => digest, :filesize => File.size(tempfile.path)
  File.copy(tempfile.path, "./files/#{@file.id}.upload")
  redirect '/'
end

get '/style.css' do
  response['Content-Type'] = 'text/css; charset=utf-8'
  sass :style
end

get '/:sha/:id' do
  @file = StoredFile.first :sha => params[:sha], :id => params[:id]
  unless params[:nowait] == 'true'
    haml :download
  else
    @file.downloads += 1
    @file.save
    send_file "./files/#{@file.id}.upload", :filename => @file.filename, :type => 'Application/octet-stream'
  end
end

# delete file
get '/:sha/:id/delete' do
  require_administrative_privileges
  @file = StoredFile.first :sha => params[:sha], :id => params[:id]
  File.delete("./files/#{@file.id}.upload")
  @file.destroy
  redirect '/'
end

C
caution, 2015-02-21
@caution

uninitialized constant Sinatra (NameError)
uninitialized constant Rack
to mean very strange labels. need experts.

A
Alexey, 2015-02-22
@fuCtor

Show init.rb Are you
using bundler?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question