I''m starting now with rails, and i have simply question i think. I need to render two partials in one ajax call: I have the following controller: # GET /hosts/1 # GET /hosts/1.json def show @host = Host.find(params[:id]) respond_to do |format| format.html #show.html format.js format.json { render :json => @host } end end And the respective template (show.js.erb): $(''#tabs-1'').html("<%= escape_javascript(render @host) %>"); And a partial file named _host.html.erb All this works fine. The template "_host.html.erb" is rendered in div tabs-1, but now i need to add some other partial template to a different id (#tabs-2), but use the same @host How can i do this? by default, render @host will use the template file _host.html.erb. How can i call a different file like "_host2.html.erb" and have the same @host instance available? Thanks, Joao -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, i''m starting now with rails, and i have simply question. I need to render two partials in one ajax call: I have the following controller: # GET /hosts/1 # GET /hosts/1.json def show @host = Host.find(params[:id]) respond_to do |format| format.html #show.html format.js format.json { render :json => @host } end end And the respective template (show.js.erb): $(''#tabs-1'').html("<%= escape_javascript(render @host) %>"); And a partial file named _host.html.erb All this works fine, but now i need to add some other partial template in a different id (#tabs-2), but use the same @host How can i do this? de default render @host will use the template file _host.html.erb. How can i call a different one like _host2.html.erb and have the same @host instance? Thanks Joao -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2012-May-21 22:17 UTC
Re: Rendering partial views with ajax calls in rails 3.1
On May 21, 1:45 pm, Joao Martins <joao.rib.mart...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m starting now with rails, and i have simply question i think. > I need to render two partials in one ajax call: > > I have the following controller: > > # GET /hosts/1 > # GET /hosts/1.json > def show > @host = Host.find(params[:id]) > > respond_to do |format| > format.html #show.html > format.js > format.json { render :json => @host } > end > end > > And the respective template (show.js.erb): > > $(''#tabs-1'').html("<%= escape_javascript(render @host) %>"); > > And a partial file named _host.html.erb > > All this works fine. The template "_host.html.erb" is rendered in div > tabs-1, but now i need to add some other partial template to a > different id (#tabs-2), but use the same @host > How can i do this? by default, render @host will use the template file > _host.html.erb. How can i call a different file like "_host2.html.erb" > and have the same @host instance available? >If you call render ''_host2'' (or render :partial => ''host2'') you''ll still be able to use @host in the template - the instance variable copying stuff is separate from the template lookup stuff Fred> Thanks, > Joao-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Walter Lee Davis
2012-May-21 22:18 UTC
Re: Rendering partial views with ajax calls in rails 3.1
On May 21, 2012, at 8:45 AM, Joao Martins wrote:> I''m starting now with rails, and i have simply question i think. > I need to render two partials in one ajax call: > > I have the following controller: > > # GET /hosts/1 > # GET /hosts/1.json > def show > @host = Host.find(params[:id]) > > respond_to do |format| > format.html #show.html > format.js > format.json { render :json => @host } > end > end > > And the respective template (show.js.erb): > > $(''#tabs-1'').html("<%= escape_javascript(render @host) %>"); > > And a partial file named _host.html.erb > > All this works fine. The template "_host.html.erb" is rendered in div > tabs-1, but now i need to add some other partial template to a > different id (#tabs-2), but use the same @host > How can i do this? by default, render @host will use the template file > _host.html.erb. How can i call a different file like "_host2.html.erb" > and have the same @host instance available?render :partial => ''_host2'', :locals => { :host2 => @host } Have a look at the Rails Guide on Views and rendering for more options. Walter> > Thanks, > Joao > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joao Martins
2012-May-22 13:21 UTC
Re: Rendering partial views with ajax calls in rails 3.1
Hi, Thank you very much 4 helping, working with render :partial => ''host2'', :locals => { :host2 => @host } cheers, João On May 21, 11:18 pm, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On May 21, 2012, at 8:45 AM, Joao Martins wrote: > > > > > > > > > > > I''m starting now with rails, and i have simply question i think. > > I need to render two partials in one ajax call: > > > I have the following controller: > > > # GET /hosts/1 > > # GET /hosts/1.json > > def show > > @host = Host.find(params[:id]) > > > respond_to do |format| > > format.html #show.html > > format.js > > format.json { render :json => @host } > > end > > end > > > And the respective template (show.js.erb): > > > $(''#tabs-1'').html("<%= escape_javascript(render @host) %>"); > > > And a partial file named _host.html.erb > > > All this works fine. The template "_host.html.erb" is rendered in div > > tabs-1, but now i need to add some other partial template to a > > different id (#tabs-2), but use the same @host > > How can i do this? by default, render @host will use the template file > > _host.html.erb. How can i call a different file like "_host2.html.erb" > > and have the same @host instance available? > > render :partial => ''_host2'', :locals => { :host2 => @host } > > Have a look at the Rails Guide on Views and rendering for more options. > > Walter > > > > > > > > > > > Thanks, > > Joao > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Reasonably Related Threads
- Refresh a partial onClick using ajax call in rails 3.x
- Finding HTML attributes with jQuery in Rails 3.1
- Rails 3 - Creating a comment and then returning the Partial with JUST the new comment
- gmaps4rails: undefined method `model_name' for NilClass:Class
- rendering a partial inside another using render_to_string and (:formats) in controller