I don't know why I cant use rake -T
or bundle exec rake -T
# app.rb
require 'rubygems'
require 'sinatra'
require "sinatra/activerecord"
class App < Sinatra::Base
#configuraciones
set :root, File.dirname(__FILE__)
set :session_secret, 'super secret'
set :public_folder, File.dirname(__FILE__) + '/public'
set :layout, 'views/layouts'
set :database, {adapter: "sqlite3", database: "data"}
enable :sessions
#before all requests
before do
headers['server'] = 'Ruby, Ubuntu'
end
#registro de helpers de la aplicacion
helpers Sinatra::App::Helpers::Applicaction
helpers Sinatra::App::Helpers::Filters
#registro de helpers de routes
helpers Sinatra::App::Helpers::ErrorHelper
#registro de rutas
register Sinatra::App::Routing::Home
register Sinatra::App::Routing::Departamento
register Sinatra::App::Routing::Provincia
register Sinatra::App::Routing::Error
end
# Rakefile.rb
require 'sinatra'
require "sinatra/activerecord/rake"
require './app'
# config.ru
require_relative 'config/boot'
require File.dirname(__FILE__) + '/app'
run App
This the error message:
PS C:\ruby\sinatra> bundle exec rake -T
WARNING: If you plan to load any of ActiveSupport's core extensions to Hash, be
sure to do so *before* loading Sinatra::Application or Sinatra::Base. If not,
you may disregard this warning.
rake aborted!
NameError: uninitialized constant Sinatra::App
C:/ruby/sinatra/app.rb:18:in `<class:App>'
C:/ruby/sinatra/app.rb:5:in `<top (required)>'
C:/ruby/sinatra/Rakefile.rb:4:in `<top (required)>'
(See full trace by running task with --trace)
PS C:\ruby\sinatra>
And here is the file structure:
#First Change app.rb
helpers Sinatra::App::Helpers::Application
#This is de helpers.rb
module Sinatra
module App
module Helpers
module Application
def load_css(csss)
rpta = ''
if defined? csss
csss.each do |css|
temp = '<link href="' + CONSTANTS[:static_url] + css + '.css" rel="stylesheet"/>'
rpta = rpta + temp
end
end
rpta
end
def load_js(jss)
rpta = ''
if defined? jss
jss.each do |js|
temp = '<script src="' + CONSTANTS[:static_url] + js + '.js" type="text/javascript"></script>'
rpta = rpta + temp
end
end
rpta
end
end
end
end
end
i have the same error
答案 0 :(得分:0)
我解决了我必须在app.rb中添加的内容
require File.dirname(__FILE__) + '/config/initializers/helpers.rb'
require File.dirname(__FILE__) + '/config/initializers/filters.rb'
require File.dirname(__FILE__) + '/helpers/error_helper.rb'
require File.dirname(__FILE__) + '/routes/error.rb'
require File.dirname(__FILE__) + '/routes/home.rb'
但是我不知道为什么我的boot.rb无法正常工作
#!/usr/bin/env rackup
# encoding: utf-8
require_relative 'config/boot'
require File.dirname(__FILE__) + '/app'
run App
#registro de rutas
Dir["./routes/*.rb"].each {|file| require file }
#registro de initializers
Dir["./config/initializers/*.rb"].each {|file| require file }
#registro de modelos
Dir["./models/*_model.rb"].each {|file| require file }
#helpers
Dir["./helpers/*_helper.rb"].each {|file| require file }