我在我的网站上使用rails_admin gem。 安装后,去localhost:3000 / admin,任何人都可以访问管理页面,我想停止它。
我使用的教程:http://amrithaprasad.com/2012/09/19/getting-started-with-rails_admin.html
首先,如果可能的话,我不想使用任何宝石,浏览后我在文件config / initializers / rails_admin.rb中找到了这个解决方案
RailsAdmin.config do |config|
ADMIN_EMAILS= ['youremail@email.com', 'email2@email.com']
config.current_user_method { current_user } # auto-generated
config.authenticate_with {} # leave it to authorize
config.authorize_with do
is_admin= ADMIN_EMAILS.include?(current_user.email)
if current_user
redirect_to main_app.new_user_session_url unless is_admin
end
end
我在这里遇到的问题是,我甚至无法启动rails服务器,我的意思是当我输入rails server
时,我遇到了一些文本错误,只有当我输入内容时才会发生错误这个文件/写这段代码。
这是我在终端中遇到的整个错误:
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load': /home/milos/RubyTest/work/thomas/projectsignal/config/initializers/rails_admin.rb:11: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `each'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `tsort_each_child'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /home/milos/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/milos/RubyTest/work/thomas/projectsignal/config/environment.rb:5:in `<top (required)>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /home/milos/RubyTest/work/thomas/projectsignal/config.ru:3:in `block in <main>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /home/milos/RubyTest/work/thomas/projectsignal/config.ru:in `new'
from /home/milos/RubyTest/work/thomas/projectsignal/config.ru:in `<main>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/server.rb:48:in `app'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/server.rb:75:in `start'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /home/milos/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
谢谢, 迈克尔
答案 0 :(得分:1)
syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
错误明确指出其期望end
关键字。
在初始化程序文件底部添加end
,因为您错过了它。
RailsAdmin.config do |config|
ADMIN_EMAILS= ['youremail@email.com', 'email2@email.com']
config.current_user_method { current_user } # auto-generated
config.authenticate_with {} # leave it to authorize
config.authorize_with do
is_admin= ADMIN_EMAILS.include?(current_user.email)
if current_user
redirect_to main_app.new_user_session_url unless is_admin
end
end
end ## Add this
答案 1 :(得分:0)
这是我输入rake routes
Prefix Verb URI Pattern Controller#Action
rails_admin /admin RailsAdmin::Engine
category_signs GET (/:locale)/categories/:category_id/signs(.:format) signs#index {:locale=>/en|sr/}
categories GET (/:locale)/categories(.:format) categories#index {:locale=>/en|sr/}
cart GET (/:locale)/carts/:cart_permalink(.:format) carts#show {:locale=>/en|sr/}
user_cart_entries GET (/:locale)/cart/entries(.:format) cart_entries#index {:locale=>/en|sr/}
POST (/:locale)/cart/entries(.:format) cart_entries#create {:locale=>/en|sr/}
user_cart_entry PATCH (/:locale)/cart/entries/:id(.:format) cart_entries#update {:locale=>/en|sr/}
PUT (/:locale)/cart/entries/:id(.:format) cart_entries#update {:locale=>/en|sr/}
DELETE (/:locale)/cart/entries/:id(.:format) cart_entries#destroy {:locale=>/en|sr/}
user_cart GET (/:locale)/cart(.:format) carts#show {:locale=>/en|sr/}
edit_current_user GET (/:locale)/profile/edit(.:format) users#edit {:locale=>/en|sr/}
current_user GET (/:locale)/profile(.:format) users#show {:locale=>/en|sr/}
PATCH (/:locale)/profile(.:format) users#update {:locale=>/en|sr/}
PUT (/:locale)/profile(.:format) users#update {:locale=>/en|sr/}
sign GET (/:locale)/signs/:id(.:format) signs#show {:locale=>/en|sr/}
page GET (/:locale)/pages/:permalink(.:format) pages#show {:locale=>/en|sr/}
GET /:locale(.:format) pages#index
root GET / pages#index
Routes for RailsAdmin::Engine:
dashboard GET / rails_admin/main#dashboard
index GET|POST /:model_name(.:format) rails_admin/main#index
new GET|POST /:model_name/new(.:format) rails_admin/main#new
export GET|POST /:model_name/export(.:format) rails_admin/main#export
bulk_delete POST|DELETE /:model_name/bulk_delete(.:format) rails_admin/main#bulk_delete
history_index GET /:model_name/history(.:format) rails_admin/main#history_index
bulk_action POST /:model_name/bulk_action(.:format) rails_admin/main#bulk_action
show GET /:model_name/:id(.:format) rails_admin/main#show
edit GET|PUT /:model_name/:id/edit(.:format) rails_admin/main#edit
delete GET|DELETE /:model_name/:id/delete(.:format) rails_admin/main#delete
history_show GET /:model_name/:id/history(.:format) rails_admin/main#history_show
show_in_app GET /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app