Is there a way to render an action into a div? i.e.: I click on a link_to_remote link, and the content of an action is put into an <div> -- 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 -~----------~----~----~----~------~----~------~--~---
Get your action to: render :text => ''Hello world'' In your page: link_to_remote(''Some Text'', :update => "my_div_id", :url => {:action => "my_action"}) Make sure your page has a <div id="my_div_id"></div> 2008/7/3 Skave Rat <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Is there a way to render an action into a div? > > i.e.: > I click on a link_to_remote link, and the content of an action is put > into an <div> > -- > Posted via http://www.ruby-forum.com/. > > > >-- ---------------------------------------- Phil Calder philcalder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org ---------------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Skave Rat wrote:> Is there a way to render an action into a div? > > i.e.: > I click on a link_to_remote link, and the content of an action is put > into an <div>Yes. You''re interested in RJS. You can do it a few ways. One is to provide the element to update in the call itself, which means you will just do a render in the controller. Another is to use render :update in the controller and specify which element gets updated. You can also use rjs partials so the updating code is not cluttering up your controller. Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe wrote:> Skave Rat wrote: >> Is there a way to render an action into a div? >> >> i.e.: >> I click on a link_to_remote link, and the content of an action is put >> into an <div> > > Yes. You''re interested in RJS. You can do it a few ways. One is to > provide the element to update in the call itself, which means you will > just do a render in the controller. Another is to use render :update in > the controller and specify which element gets updated. You can also use > rjs partials so the updating code is not cluttering up your controller. > > Peace, > PhillipI tried RJS and :update, but it didn''t really workt. could you provide me a small example? -- 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 -~----------~----~----~----~------~----~------~--~---
Skave Rat wrote:> > I tried RJS and :update, but it didn''t really workt. could you provide > me a small example?Sure. app/controllers/time_controller.rb class TimeController < ApplicationController def index end def now render :update do |page| page.replace_html :current_time, Time.now end end end app/views/time/index.html.erb <%= link_to_remote ''Current Time'', :url => {:controller => :time, :action => :now} %> <div id="current_time"> </div> Run script/server, navigate to http://localhost:3000/time, and click the Current Time link. You should see the current time appear right below the link. Click it again and you should see the time refresh. If the code gets munged, I''ll post again with something that will not be technically correct but will hopefully be useful. Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe wrote:> Skave Rat wrote: >> >> I tried RJS and :update, but it didn''t really workt. could you provide >> me a small example? > > Sure. > > app/controllers/time_controller.rb > > class TimeController < ApplicationController > def index > end > > def now > render :update do |page| > page.replace_html :current_time, Time.now > end > end > end > > app/views/time/index.html.erb > > <%= link_to_remote ''Current Time'', :url => {:controller => :time, > :action => :now} %> > > <div id="current_time"> > </div> > > Run script/server, navigate to http://localhost:3000/time, and click the > Current Time link. You should see the current time appear right below > the link. Click it again and you should see the time refresh. > > If the code gets munged, I''ll post again with something that will not > be technically correct but will hopefully be useful. > > Peace, > Phillipwell, that''s nothing new to me. My problem is rendering a view or HTML template into a div. i.e.: you have following in your opened page: <div id="div1"></div> and I want to add this snippet into it: <h1>Hello @User.id</h1> <p>Lorem ipsum dolor sit amet...</p> is that possible? -- 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 -~----------~----~----~----~------~----~------~--~---
The other way to do it (specifying the element to update in the call) would be done like this: app/controllers/time_controller.rb def now render :text => Time.now.to_s end Note that render :text can also be render :inline. They both seem to have the same result, but I don''t know if the implementation of one is better than the other. app/views/time/index.html.erb <%= link_to_remote ''Current Time'', :url => {:controller => :time, :action => :now}, :update => :current_time %> <div id="current_time"> </div> I''m not really sure why, but I prefer the render :update method. You can also render partials: render :partial => ''path/to/partial'' or render :update do |page| page.replace_html :element_to_update, :partial => ''path/to/partial'' end And of course, you can use all of the normal caveats of partials (:collection, :object, :locals, :layout => false, etc). Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
> > well, that''s nothing new to me.Hm. Okay. Sorry I insulted your intelligence. You asked for a small example. I showed you one.> My problem is rendering a view or HTML > template into a div. i.e.: > you have following in your opened page: > <div id="div1"></div> > > and I want to add this snippet into it: > > <h1>Hello @User.id</h1> > <p>Lorem ipsum dolor sit amet...</p> > > > is that possible?Yes. I posted another message that indicated you can use partials. As far as I know, you cannot use a standard view. It must be a partial. I might be wrong in that, though. The AJAX call will be the same (and you can pass parameters if you need to), and in the controller action, do whatever you need to, and render a partial. I do this in a situation in which I''m editing a resource. Suppose I have a widget that I want to edit, I might have a form that looks like <% @widgets.each do |widget| %> <%= widget.name %> link_to_remote ''(Edit)'', :controller => :widgets, :action => :edit, :id => widget.id %> <%= "<div id=''widget_#{widget.id}''>" %> </div> <% end %> Then in the controller def edit widget = Widget.find_by_id(params[:id]) render :update do |page| page.replace_html "widget_#{widget.id}", :partial => ''widget'', :object => widget end end Does that help? Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
It helps me!! On Jul 3, 3:36 am, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > well, that''s nothing new to me. > > Hm. Okay. Sorry I insulted your intelligence. You asked for a small > example. I showed you one. > > > My problem is rendering a view or HTML > > template into a div. i.e.: > > you have following in your opened page: > > <div id="div1"></div> > > > and I want to add this snippet into it: > > > <h1>Hello @User.id</h1> > > <p>Lorem ipsum dolor sit amet...</p> > > > is that possible? > > Yes. I posted another message that indicated you can use partials. As > far as I know, you cannot use a standard view. It must be a partial. I > might be wrong in that, though. The AJAX call will be the same (and you > can pass parameters if you need to), and in the controller action, do > whatever you need to, and render a partial. > > I do this in a situation in which I''m editing a resource. Suppose I have > a widget that I want to edit, I might have a form that looks like > > <% @widgets.each do |widget| %> > <%= widget.name %> link_to_remote ''(Edit)'', :controller => :widgets, > :action => :edit, :id => widget.id %> > <%= "<div id=''widget_#{widget.id}''>" %> > </div> > <% end %> > > Then in the controller > > def edit > widget = Widget.find_by_id(params[:id]) > render :update do |page| > page.replace_html "widget_#{widget.id}", :partial => ''widget'', > :object => widget > end > end > > Does that help? > > Peace, > Phillip > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Which one is better making an RJS or using def edit widget = Widget.find_by_id(params[:id]) render :update do |page| page.replace_html "widget_#{widget.id}", :partial => ''widget'', :object => widget end end I always prefer RJS , because it makes debugging easier and my controller a bit less clustered. Check the API about RJS you will get many examples and all other help needed. ----------- On Jul 3, 4:10 am, "Phil Calder" <philcal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Get your action to: > render :text => ''Hello world'' > > In your page: > link_to_remote(''Some Text'', :update => "my_div_id", :url => {:action => > "my_action"}) > > Make sure your page has a <div id="my_div_id"></div> > > 2008/7/3 Skave Rat <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > > > > > Is there a way to render an action into a div? > > > i.e.: > > I click on a link_to_remote link, and the content of an action is put > > into an <div> > > -- > > Posted viahttp://www.ruby-forum.com/. > > -- > ---------------------------------------- > Phil Calder > philcal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > ------------------------------------------~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Web Blogger wrote:> Which one is better making an RJS or using > > def edit > widget = Widget.find_by_id(params[:id]) > render :update do |page| > page.replace_html "widget_#{widget.id}", :partial => ''widget'', > :object => widget > end > end >As I understand it, this *is* RJS, just not using an RJS template, such as edit.js.erb> > I always prefer RJS , because it makes debugging easierThat, I believe, is a personal opinion. 90-some-odd percent of my debugging happens in controllers, and I like to have related code handy. I often make some decisions inside the render :update block, and it''s easier _for me_ to have it in the controller.> and my > controller a bit less clustered.It depends on a lot of things. I often grow weary of bouncing around from file to file, as I tend to use a lot of view partials. When I have one or two lines of code to respond to an ajax call, it doesn''t bother me to have it in the controller. I know there are _best practices_, but at the end of the day, I have to get work done and be happy doing it. No two programmers are exactly alike, and one of the things I like about Rails is that it allows a certain something-or-other to be done in a variety of ways, but still with programmer happiness in mind. Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---