Hi, just looking for "best practice" guidance... I have a controller method that renders its output with an rhtml view file. The output can also be updated via an rjs update via an rjs view file. I can''t work out if it is possible to have action.rhtml AND action.rjs and have the correct one called depending on the request. SO, I have done this: if I have have "my_action.rhtml" and "my_action_update.rjs", then the controller method is :- def my_action .... action code... render :action => :my_action_update if request.xhr? end This works, but is it the right way, or is there a better way? Comments appreciated :) -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Lane napisaĆ(a):> Hi, just looking for "best practice" guidance... > > I have a controller method that renders its output with an rhtml view > file. The output can also be updated via an rjs update via an rjs view > file. > > I can''t work out if it is possible to have action.rhtml AND action.rjs > and have the correct one called depending on the request. SO, I have > done this: > > if I have have "my_action.rhtml" and "my_action_update.rjs", > then the controller method is :- > > def my_action > .... action code... > > render :action => :my_action_update if request.xhr? > end > > This works, but is it the right way, or is there a better way? > > Comments appreciated :) > -- > Posted via http://www.ruby-forum.com/.Try "respond_to" - http://api.rubyonrails.com/classes/ActionController/MimeResponds/InstanceMethods.html#M000206. def action ...action code... respond_to do |format| format.html # renders action.rhtml format.js # renders action.rjs end end --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
> Try "respond_to" -Yes this worked, thanks! Actually, it didn''t work straight off. I discovered it only works if the files are called "action.html.rhtml" and "action.js.rjs" instead of "action.rhtml" and "action.rjs". I googled and found that this naming dependency was introduced with rails 2.0.2. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---