In my edit page: url = profile/:id/edit
the content is !
<%= form_for(@user, :as => :user, :url => profile_path(current_user),
:html=>{:method => :put}) do |form| %>
<%= form.text_field :email, :class=>“input”%>
<%= form.submit ‘Update Profile’%>
<% end %>
…
In controller section !
class ProfileController < ApplicationController
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
@user.email = params[:user][:email]
@user.save
respond_to do |format|
if @user.save = @user.update_attributes(params[:user])
if @user.update_attributes(params[:user])
format.html {redirect_to(profile_path(@user), :notice => 'User
was successfully updated.’)}
else
format.html { render action: “index” }
end
end
end
…
In Route …
match “/profile/:id” => “profile#index”, :as => :profile
match “/profile/:id/edit” => “profile#edit”, :as => :profile_edit
put ‘/profile/:id’ => “profile#update” ## method = put for update
…
In Model - update data be saved in user table.
…
But I can’t update data . In rails server screen , I see the edit
process.I can’t see update process - like " Update user where
…"
Pls give me a hand!!!
On 6 April 2012 10:01, phoe san [email protected] wrote:
respond_to do |format|
end
…
You need to look through the update method and ask yourself what each
line is doing. For example you seem to have two save calls and also
two update_attributes (which updates the object and saves it). That
is four saves all together. is that what you meant to do?
Then if it still does not work check in development.log to make sure
the action is being called with the correct parameters, then if still
not working debug into the update action to see what is going on.
Have a look at the Rails Guide on Debugging if you do not know how to
do that.
Colin
On Apr 6, 10:01am, phoe san [email protected] wrote:
In Route …
match “/profile/:id” => “profile#index”, :as => :profile
match “/profile/:id/edit” => “profile#edit”, :as => :profile_edit
put ‘/profile/:id’ => “profile#update” ## method = put for update
Your update action looks a little confused - it’s updating the record
4 times which seems overkill, but it looks like you’re not ever
getting to the update action - if you were an exception would be
raised at the point where you do @user.save = … (since there is no
save= method)
match (by default) accepts all http verbs, so when your put request
comes through it gets routed to profile#index. routes are considered
in the order they are defined, so although you do have a put specific
route, rails never even looks at it because it finds match ‘/
profile/:id’ first.
You should either make the route to index action more specific (i.e.
say that it has to be a GET) or move the route to the update index
before it
Fred
Thank Fred!
routes are considered in the order they are defined, so although you do
have a put specific route, rails never even looks at it because it finds
match ‘/
profile/:id’ first…
This logic fix my error.
phoesan