How I handled the scenario of creating new users, if you logged in, a user controller was created and a new one was created and created action methods that would be stored in the User model. (This was shot from the current application I'm working on, hope I haven't missed 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| %> <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 the new user’s page
<%= link_to 'New User', new_user_path %>
source share