Hello, I don''t really know how to solve following problem: When I access .../users/1 I get the website and the user is shown properly, all good. I have some link_to_remote actions on my website and when they call the /users/1 action I - of course - get the whole page rendered despite I just wanted to update a div with only name being displayed. My question now is how it''s possible to determine within the action if it''s an HTTP or AJAX request and render accordingly (full layout for HTTP and only one DIV box for the AJAX request). How would you solve that kind of problem? Thank you, Heinz -- Posted via http://www.ruby-forum.com/.
On Sep 19, 12:39 pm, Heinz Strunk <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > > I don''t really know how to solve following problem: When I access > .../users/1 I get the website and the user is shown properly, all good. > I have some link_to_remote actions on my website and when they call the > /users/1 action I - of course - get the whole page rendered despite I > just wanted to update a div with only name being displayed. My question > now is how it''s possible to determine within the action if it''s an HTTP > or AJAX request and render accordingly (full layout for HTTP and only > one DIV box for the AJAX request). >I''m sure you know this but AJAX requests are of course http requests :-). There''s the xml_http_request? method (also available as xhr? ) and of course respond_to is designed for this sort of stuff. Fred> How would you solve that kind of problem? > > Thank you, > Heinz > -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On Sep 19, 12:39�pm, Heinz Strunk <rails-mailing-l...@andreas-s.net> > wrote: >> > I''m sure you know this but AJAX requests are of course http > requests :-). > > There''s the xml_http_request? method (also available as xhr? ) and of > course respond_to is designed for this sort of stuff. > > FredYeah I know I just didn''t no how to call these two requests :) I''ll have a look at that xhr? thing. Thanks Frederick! -- Posted via http://www.ruby-forum.com/.
Hi Heinz, On Sat, 2009-09-19 at 13:39 +0200, Heinz Strunk wrote:> Hello, > > I don''t really know how to solve following problem: When I access > .../users/1 I get the website and the user is shown properly, all good. > I have some link_to_remote actions on my website and when they call the > /users/1 action I - of course - get the whole page rendered despite I > just wanted to update a div with only name being displayed. My question > now is how it''s possible to determine within the action if it''s an HTTP > or AJAX request and render accordingly (full layout for HTTP and only > one DIV box for the AJAX request). > > How would you solve that kind of problem?I may be misunderstanding your question but I think you just need to wrap the rendering, and potentially some of the actual logic, in a respond_to block. respond_to do |format| { format.html { ... } format.js { ...} end HTH, Bill
On Mon, Sep 21, 2009 at 9:53 PM, bill walton <bwalton.im-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi Heinz, > > On Sat, 2009-09-19 at 13:39 +0200, Heinz Strunk wrote: >> Hello, >> >> I don''t really know how to solve following problem: When I access >> .../users/1 I get the website and the user is shown properly, all good. >> I have some link_to_remote actions on my website and when they call the >> /users/1 action I - of course - get the whole page rendered despite I >> just wanted to update a div with only name being displayed. My question >> now is how it''s possible to determine within the action if it''s an HTTP >> or AJAX request and render accordingly (full layout for HTTP and only >> one DIV box for the AJAX request). >> >> How would you solve that kind of problem? > > I may be misunderstanding your question but I think you just need to > wrap the rendering, and potentially some of the actual logic, in a > respond_to block. > > respond_to do |format| { > format.html { ... } > format.js { ...} > endrespond_to selects what''s to be rendered not on whether it''s an ajax request or not, but by the acceptable mime types in the request. An ajax request might be requesting html. request.xhr? is the proper way to detect an ajax request. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale