views:

19

answers:

1

I am new to Rails.

I have a User model. I would like a web page that allows users to change their :name and :email, and another web page that allows them to change their password.

Right now, I have a form to edit :name and :email at

/users/1/edit

The form on the page is

<%= form_for(@user) do |f| %>

My routes.rb has

resources :users

This works. Users can edit their :name and :email just fine. How do I now set up another web page with another form that allows them to change their password?

Thank you.

A: 

You can set up any actions you like in your controller. The default CRUD operations are there to cover the basics, but there is no inherent limitation to what you can do.

#controller:
def change_password
  render :action => "change_password"
end 

#routes:
map.resource :users, :member => {:change_password => :get}

#view:
<%= form_for(@user) do |f| %>

The above would create the route: /users/1/change_password

In the view you simply have the change password fields => the form basically stays the same, submitting to your existing update action.

Toby Hede
Thank you, Toby. I'm using Rails 3 so the syntax is a bit different, but this was enough of a pointer to get me going.
Sanjay