Fab*_*bio 16 routes ruby-on-rails devise
我正在编写一个rails应用程序,其中我有一个编辑器和一个出版物模型.我正在使用设计编辑器身份验证,并且由于编辑器不能作为访客执行任何操作,因此我编写了一个用于登录页面的自定义布局,并且我希望访客用户只能看到登录页面.
现在,我正在尝试在我的应用程序中实现以下行为,但未成功:
require 'spec_helper'
require 'capybara/rails'
describe "Authentication" do
describe "when logged in" do
before(:each) do
@editor = Factory(:editor, :password => 'secret')
visit '/'
fill_in 'Login', :with => @editor.login
fill_in 'Password', :with => 'secret'
click_button 'Sign in'
page.should have_content('Signed in successfully.')
end
it "getting / should render publication page with no redirection" do
visit '/'
page.should_not have_content('Login')
page.should have_content('Publications')
# assert that there is no redirection
page.current_path.should == '/'
end
it "visits the sign_in page should redirect to /" do
visit '/editors/sign_in'
page.should have_content('Publications')
page.current_path.should == '/'
end
end
describe "when not logged in" do
it "getting / should not display the sign in warning" do
visit '/'
# I want to get rid of this message
page.should_not have_content('You need to sign in or sign up before continuing.')
end
it "getting / should not redirect to the sign_in default page" do
visit '/'
page.should have_content('Login')
# assert that there is no redirection
page.current_path.should == '/'
end
it "getting the the sign_in default path works" do
visit '/editors/sign_in'
page.should have_content('Login')
page.current_path.should == '/editors/sign_in'
end
it "login works and redirect me to the publications page (with /)" do
@editor = Factory(:editor, :password => 'secret')
visit '/'
fill_in 'Login', :with => @editor.login
fill_in 'Password', :with => 'secret'
click_button 'Sign in'
page.should have_content('Signed in successfully.')
page.current_path.should == '/'
page.should have_content('Publications')
end
end
end
Run Code Online (Sandbox Code Playgroud)
主要问题是我想摆脱"你需要在继续之前登录或注册".访客用户访问'/'时的消息.
有关如何实现此设计的任何提示?
谢谢.
wil*_*key 28
我认为你应该使用类似的东西
authenticated :user do
root :to => 'users#index', as: :authenticated_root
end
root :to => 'welcome#index'
Run Code Online (Sandbox Code Playgroud)
由于rails4不允许具有相同名称的路由,因此需要指定为:
Fab*_*bio 24
这篇文章解释了如何实现:
authenticated :user do
root :to => "main#dashboard"
end
root :to => "main#index"
Run Code Online (Sandbox Code Playgroud)
以下是执行此操作的pull请求以及一些技术细节
authenticated :user do
root :to => 'home#index', :as => :authenticated_root
end
root :to => redirect('/users/sign_in')
Run Code Online (Sandbox Code Playgroud)
直接来自马的嘴巴,如何为设计宝石.:d
归档时间: |
|
查看次数: |
10141 次 |
最近记录: |