Rails Devise: How to access sign up page after signed in?

后端 未结 3 1354
我寻月下人不归
我寻月下人不归 2021-02-10 07:46

I am new with rails and i am using \"devise\" gem for authentication purposes.

At first i add a new user through default sign up page (E.g./users/sign_up)

Then,

3条回答
  •  借酒劲吻你
    2021-02-10 08:20

    The way I handled the scenario of being able to create New Users if you are signed in was by generating a User controller and having new and create action methods that would save to the User model. (This was stripped from a current app I'm working on so hopefully I didn't miss anything)

    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
    

    views/user/new.html.erb

    <%= form_for @user, :url => user_index_path do |f| %>
      

    <%= f.label :email %> <%= f.text_field :email %>

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

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

    <%= f.submit "Save" %>

    <% end %>

    config/routes.rb (Rails 3)

    resources :user, :controller => "user"
    

    Link to the New User page

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

提交回复
热议问题