Rails 3 - Setting up an Account Controller w Views
I have a Rails 3 App with Devise...
I want to create a Account controller that will allow the user to update their account, things like Profile, Account, Notices, Password, etc...
Here's what I've done so far.
I generated an account controller wh开发者_StackOverflowich gave me the following:
Routes:
get "account/profile"
get "account/password"
get "account/notices"
Views now exists given the names above with /views/account/...
My Controller
class AccountController < ApplicationController
before_filter :authenticate_user!
def profile
@user = User.find(current_user.id)
end
def password
end
def notices
end
def privacy
end
def disable
end
end
View for Account Profile:
<% form_for @user, :html => { :multipart => true} do |f| %>
Problem is that makes the form like:
<form accept-charset="UTF-8" action="/users/13" class="edit_user" enctype="multipart/form-data" id="edit_user_13" method="post">
And I want it to be like /account/profile/update
which is where the form should post?
This is the first time I've done something like this. Am I down the right track? How do I add the /account/profile/update part? Add something in the route and change the form tag??? Is there a cleaner way to do this in the route?
Thank you
You should stick to RESTful routes when possible. Instead of having URLs like /profile/123/update
, the RESTful alternative would be /profile/123
using HTTP PUT
read this for more info on RESTful routes in Rails 3: http://edgeguides.rubyonrails.org/routing.html
Also, take a look at using nested resources in your routes for profiles, notices, etc (section 2.7 in the rails doc):
resources :accounts do
resources :profiles, :notices
end
For example, doing an edit using a nested resource will give you routes like this:
/accounts/123/notices/3/edit
精彩评论