[英]rails_admin can't get auth working
I am using rails_admin gem for my website. 我在我的网站上使用rails_admin gem。 After installing it, and going localhost:3000/admin, anyone can access the admin page, and I want to stop that. 安装它并进入localhost:3000 / admin后,任何人都可以访问admin页面,我想停止该页面。
Tutorial I used: http://amrithaprasad.com/2012/09/19/getting-started-with-rails_admin.html 我使用的教程: http : //amrithaprasad.com/2012/09/19/getting-started-with-rails_admin.html
First I'd like to use no gems if its possible, and after browsing I've found this solution in file config/initializers/rails_admin.rb 首先,我尽可能不使用gem,浏览后,我在文件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
the issue I'm having here, is that I can't even start a rails server, I mean when I type rails server
I get some wall of text errors, which is happening only when I type something into this file/writing this code. 我在这里遇到的问题是,我什至无法启动Rails服务器,我的意思是,当我输入rails server
我会遇到一些文字错误,只有当我在此文件中键入某些内容/编写此代码时才会发生这种错误。
This is the entire error I get in terminal : 这是我在终端中遇到的整个错误:
=> 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>'
Thanks, Michael 谢谢迈克尔
syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
error clearly states that its expecting end
keyword. syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
错误明确指出了其预期的end
关键字。
Add an end
at the bottom of your initializer file as you are missing it. 缺少初始化器文件时,请在其底部添加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
This is what i get after i type rake routes
这是我输入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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.