Hi guys, I''m starting to meddle a bit with the inbuilt Ajax functionality that Rails offers, and would like a little help of possible! I have following Ajax link: <%= link_to_remote "read", :update => ''wrapper'', :url => {:action => ''read_message'', :id => message.id} %> which calls this action: def read_message render(:layout => false) @the_message = Message.find(params[:id]) end but when I try to use @the_message in read_message.rhtml it throws errors (and if I dump the contents within that view''s RHTML it is empty). Is there a solution to this? Cheers, Mick -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Mick, please provide the relevant view code. Thanks, -Conrad On 4/1/07, Mick <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi guys, I''m starting to meddle a bit with the inbuilt Ajax > functionality that Rails offers, and would like a little help of > possible! > > I have following Ajax link: > > <%= link_to_remote "read", :update => ''wrapper'', :url => {:action => > ''read_message'', :id => message.id} %> > > which calls this action: > > def read_message > render(:layout => false) > @the_message = Message.find(params[:id]) > end > > but when I try to use @the_message in read_message.rhtml it throws > errors (and if I dump the contents within that view''s RHTML it is > empty). > > Is there a solution to this? > > Cheers, > > Mick > > -- > 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 -~----------~----~----~----~------~----~------~--~---
On Apr 1, 5:47 pm, Mick <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi guys, I''m starting to meddle a bit with the inbuilt Ajax > functionality that Rails offers, and would like a little help of > possible! > > I have following Ajax link: > > <%= link_to_remote "read", :update => ''wrapper'', :url => {:action => > ''read_message'', :id => message.id} %> > > which calls this action: > > def read_message > render(:layout => false) > @the_message = Message.find(params[:id]) > end > > but when I try to use @the_message in read_message.rhtml it throws > errors (and if I dump the contents within that view''s RHTML it is > empty).Remember, that render call you have will force rails to render the template at that moment. Just try putting the render call as the last statement in your method, *after* you set your variables. Jeff softiesonrails.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 -~----------~----~----~----~------~----~------~--~---
Hi Conrad! Thanks for the reply so soon, I just this second pinpointed the problem. I placed render(:layout => false) on the last line of the "read_message" action in the controller and now I can access the data in @the_message, Cheers, Mick -- 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 -~----------~----~----~----~------~----~------~--~---
Yep - found that out with a bot of work, cheers -- 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 -~----------~----~----~----~------~----~------~--~---
Also sometimes is better to use rjs file instead of rendering rhtml, Like if you have loading indicator and you need update two or moder DOM''s elements, Sample: in form_rhtml: BlaBla... <div style="display: none" id="loading">Loading..</div> <div id="total_comments">2</div> <div id="comments">comments here</div> <%= form_remote_tag :url => {:controller => ''article'', :action => ''addComment'', :id => article.id }, :loading => "Element.show(''loading''), :complete => "Element.hide(''loading'') } %> ... form goes here with end form tag,,.... Now in action you are saving posted comments, .... in addComment.rjs: page.replace_html ''total_comments'', @comments.size page.replace_html ''comments'', :partial => "comments" Thats all, (mayb i misspelled something, but that''s a way) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---