Ruby on Rails Wednesday, December 1, 2010

Le 1 décembre 2010 18:12:01 UTC+2, Leonel *.* <lists@ruby-forum.com> a écrit :
ALRIGHT!! AWESOME!!!

Simple and it works!

I did this...

flash[:notice] = 'User was successfully updated.'
respond_to do |format|
 if @user.update_attributes(params[:user])
   format.html { redirect_to(:action => 'edit') }
   format.xml  { head :ok }
 else
...

Thanks Colin!

I have come in this conversion late but I can still contribute.

You may wish to know whether the user was sucessfully updated or not. So I guess (1) your flash[:notice] is ill-positioned, and (2) you need to have an "error dispatcher" too. In addition, I am not sure if you "really" want to conditional processing of HTTP (I mean do you really need to specify that the application should respond to html format?).

But combining the solutions above (from the previous threads) plus my changes, we have the following:

1. In you controller:

respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to(:action => 'edit' ) }
else
flash[:error] = 'User was not updated.'
format.html { redirect_to(:action => 'edit' ) }
end
end

2. In your layout, you may wish to add the following lines to track the "flash" messages:

<p style="color: green"><%= flash[:notice] %></p>
<p style="color: red"><%= flash[:error] %></p>

More blessings,

---
Edmond
Software Developer | Baobab Health Trust (http://www.baobabhealth.org/) | Malawi

Cell:  +265 999 465 137 | +265 881 234 717

"Leading the Improvement of Health through Information and Communication Technology in the Developing World" The Creed of Baobab Health
 

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

No comments:

Post a Comment