加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails设计:登录后如何访问注册页面?

发布时间:2020-12-17 03:09:58 所属栏目:百科 来源:网络整理
导读:我是rails的新手,我使用“devise”gem进行身份验证. 首先,我通过默认注册页面添加新用户(例如,/ users / sign_up) 然后,我通过以下说明向signed_in用户提供“sign_up”页面 Devise before filter that prevents access to “new_user_registration_path” un
我是rails的新手,我使用“devise”gem进行身份验证.

首先,我通过默认注册页面添加新用户(例如,/ users / sign_up)

然后,我通过以下说明向signed_in用户提供“sign_up”页面

Devise before filter that prevents access to “new_user_registration_path” unless user is signed-in

现在,在我尝试打开注册页面登录过程后,它总是指示我到root_path!我如何访问注册页面?
我的“roots.rb”文件如下:

Example::Application.routes.draw do

  devise_for :users,:controllers => { :registrations => 'registrations'}

  resources :companies

  resources :orders

  resources :customers

  root :to => "welcome#index"

end

谢谢你们!

解决方法

如果您已登录,我处理能够创建新用户的方案的方法是生成用户控制器并使用新的和创建操作方法来保存到用户模型. (这是从我正在处理的当前应用程序中删除的,所以希望我没有错过任何内容)

user_controller.rb

def new
  @user = User.new
end

def create
  @user = User.new(params[:user])

  if @user.save
    flash[:notice] = "Successfully created User." 
    redirect_to root_path
  else
    render :action => 'new'
  end
end

视图/用户/ new.html.erb

<%= form_for @user,:url => user_index_path do |f| %>
  <p><%= f.label :email %>
  <%= f.text_field :email %></p>

  <p><%= f.label :password  %>
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation  %>
  <%= f.password_field :password_confirmation %></p>

  <p><%= f.submit "Save" %></p>
<% end %>

config / routes.rb(Rails 3)

resources :user,:controller => "user"

链接到“新用户”页面

<%= link_to 'New User',new_user_path %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读