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!!!!!!!

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Apr 6, 2012 at 10:21 am

    On 6 April 2012 10:01, phoe san wrote:
    ...
    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
    ...........
    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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Frederick Cheung at Apr 6, 2012 at 10:26 am

    On Apr 6, 10:01 am, phoe san 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
    Pls give me a hand!!!!!!!

    --
    Posted viahttp://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Phoe san at Apr 6, 2012 at 10:53 am
    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

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 6, '12 at 9:01a
activeApr 6, '12 at 10:53a
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase