Hey all, Is there a way to specify which RJS template to use for an action? Similar to render :template => "template". I''ve got an action that I need to have render different templates within the same action. Due to a front-end Mongrel plugin I don''t want to have an action for each template like you would normally. As far as I can tell, you can only have one RJS template for an action, is that true? Thanks! -- Thermal Creative http://blog.thermalcreative.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 -~----------~----~----~----~------~----~------~--~---
I''ve used render :template => "someothertemplate" with rjs plenty of times, never been a problem here. Fred -- 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 14 November 2006 11:43, Matt White wrote:> Is there a way to specify which RJS template to use for an action? Similar > to render :template => "template". I''ve got an action that I need to have > render different templates within the same action. Due to a front-end > Mongrel plugin I don''t want to have an action for each template like you > would normally. As far as I can tell, you can only have one RJS template > for an action, is that true?if foo render :action => ''one.rjs'' else render :action => ''another.rjs'' end Actually, you can use extensions when you do usual render: render :action => ''foo.rhtml'' If no extension given, it deduces it. In fact, the :action argument doesn''t mean that it will somehow render an action. It means that it will use template with given name that should be located in template folder for current controller. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matt, I would recommending reading and completing the tutorials of "RJS Templates for Rails" by Cody Fauser because it provides a wealth of information on RJS. BTW, the answer to your question is answered on page 4. Good luck, -Conrad On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey all, > > Is there a way to specify which RJS template to use for an action? Similar > to render :template => "template". I''ve got an action that I need to have > render different templates within the same action. Due to a front-end > Mongrel plugin I don''t want to have an action for each template like you > would normally. As far as I can tell, you can only have one RJS template for > an action, is that true? > > Thanks! > > -- > Thermal Creative > http://blog.thermalcreative.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 -~----------~----~----~----~------~----~------~--~---
Thanks all... I''ve got Cody''s book, but that part apparently didn''t stick :). And I did use render :template => "rjstemplate", and I got an error thrown that it couldn''t find rjstemplate.rhtml, so it appeared that the render was automatically extending the filename to .rhtml. I''ll check out Cody''s solution... Matt On 11/14/06, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Matt, I would recommending reading and completing the tutorials of > "RJS Templates for Rails" by Cody Fauser because it provides a wealth > of information on RJS. BTW, the answer to your question is answered > on page 4. > > Good luck, > > -Conrad > > On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey all, > > > > Is there a way to specify which RJS template to use for an action? > Similar > > to render :template => "template". I''ve got an action that I need to > have > > render different templates within the same action. Due to a front-end > > Mongrel plugin I don''t want to have an action for each template like you > > would normally. As far as I can tell, you can only have one RJS template > for > > an action, is that true? > > > > Thanks! > > > > -- > > Thermal Creative > > http://blog.thermalcreative.com > > > > > > > > >-- Thermal Creative http://blog.thermalcreative.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 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve got Cody''s book, but that part apparently didn''t stick :). And I did > use render :template => "rjstemplate", and I got an error thrown that it > couldn''t find rjstemplate.rhtml, so it appeared that the render was > automatically extending the filename to .rhtml.Rails searches for templates in some order. I believe, it first tries to find .rhtml file, then, perhaps, .rxml and .rjs. Concerning your problem: make sure you are using latest Rails release. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maxim, I used your original render :action => "template.rjs" option, and that works fine. I''m on Edge, but when I try render :template => "template" or render :template => "template.rjs" assert_existence_of_template_file throws a MissingTemplate error because it''s looking for the wrong file type (rhtml). For some reason Cody''s book has dropped out of Safari and my bookshelf, so I can''t verify what his method was. I''ve sent O''Reilly an email, but they haven''t fixed it yet. Matt On 11/15/06, Maxim Kulkin <maxim.kulkin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve got Cody''s book, but that part apparently didn''t stick :). And I > > did use render :template => "rjstemplate", and I got an error thrown that it > > couldn''t find rjstemplate.rhtml, so it appeared that the render was > > automatically extending the filename to .rhtml. > > > Rails searches for templates in some order. I believe, it first tries to > find .rhtml file, then, perhaps, .rxml and .rjs. > > Concerning your problem: make sure you are using latest Rails release. > > > > >-- Thermal Creative http://blog.thermalcreative.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 -~----------~----~----~----~------~----~------~--~---
> > I''ve got Cody''s book, but that part apparently didn''t stick :). And I did > use render :template => "rjstemplate", and I got an error thrown that it > couldn''t find rjstemplate.rhtml, so it appeared that the render was > automatically extending the filename to .rhtml.render :template => "rjstemplate", :type => :rjs -philip> > I''ll check out Cody''s solution... > > Matt > > On 11/14/06, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> Matt, I would recommending reading and completing the tutorials of >> "RJS Templates for Rails" by Cody Fauser because it provides a wealth >> of information on RJS. BTW, the answer to your question is answered >> on page 4. >> >> Good luck, >> >> -Conrad >> >> On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> Hey all, >>> >>> Is there a way to specify which RJS template to use for an action? >> Similar >>> to render :template => "template". I''ve got an action that I need to >> have >>> render different templates within the same action. Due to a front-end >>> Mongrel plugin I don''t want to have an action for each template like you >>> would normally. As far as I can tell, you can only have one RJS template >> for >>> an action, is that true? >>> >>> Thanks! >>> >>> -- >>> Thermal Creative >>> http://blog.thermalcreative.com >>> > >>> >> >>> >> > > > -- > Thermal Creative > http://blog.thermalcreative.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 -~----------~----~----~----~------~----~------~--~---
Hmmm... I''m looking @ the code for action_controller/base and it seems that :type only gets taken into account when rendering inline templates, not file-based ones. Suffice it to say, I got the same file-type extension error I did before, where it puts .rhtml onto the end instead of .rjs. render :action => "template.rjs" works because render_action takes into account the .rjs extension and renders it without layout by default... It seems like at this point the best option is the render :action => " template.rjs". Thanks, though! Matt On 11/15/06, Philip Hallstrom <rails-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > > > > > I''ve got Cody''s book, but that part apparently didn''t stick :). And I > did > > use render :template => "rjstemplate", and I got an error thrown that it > > couldn''t find rjstemplate.rhtml, so it appeared that the render was > > automatically extending the filename to .rhtml. > > render :template => "rjstemplate", :type => :rjs > > -philip > > > > > I''ll check out Cody''s solution... > > > > Matt > > > > On 11/14/06, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> > >> Matt, I would recommending reading and completing the tutorials of > >> "RJS Templates for Rails" by Cody Fauser because it provides a wealth > >> of information on RJS. BTW, the answer to your question is answered > >> on page 4. > >> > >> Good luck, > >> > >> -Conrad > >> > >> On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> Hey all, > >>> > >>> Is there a way to specify which RJS template to use for an action? > >> Similar > >>> to render :template => "template". I''ve got an action that I need to > >> have > >>> render different templates within the same action. Due to a front-end > >>> Mongrel plugin I don''t want to have an action for each template like > you > >>> would normally. As far as I can tell, you can only have one RJS > template > >> for > >>> an action, is that true? > >>> > >>> Thanks! > >>> > >>> -- > >>> Thermal Creative > >>> http://blog.thermalcreative.com > >>> > > >>> > >> > >>> > >> > > > > > > -- > > Thermal Creative > > http://blog.thermalcreative.com > > > > > > > > > > >-- Thermal Creative http://blog.thermalcreative.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 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Maxim, > > I used your original render :action => "template.rjs" option, and that > works fine. I''m on Edge, but when I try render :template => "template" or > render :template => "template.rjs " assert_existence_of_template_file > throws a MissingTemplate error because it''s looking for the wrong file type > (rhtml).Difference between render :action => and render :template => is that template is searched relative to TEMPLATE ROOT (which is RAILS_ROOT/app/views by default). So to use render :template => you should supply proper path, e.g. render :template => ''mycontroller/template.rjs''. Hope that helps. --~--~---------~--~----~------------~-------~--~----~ 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, makes perfect sense. I confirmed that by looking at the ActionController::Base source... It does a simple check for existence to see if the file exists based solely on the path passed to :template, and if it doesn''t then it calls @template.send(:full_template_path, template_name, ''rhtml'') to get the file name. Interestingly, the last parameter on full_template_path is the file type. So, I wonder if a simple fix to this problem would be to have it also accept the :type parameter as was mentioned previously on this thread. Then you could just do render :template => "filename", :type => :rjs and it would actually work. Either way, it seems that :action is the most concise solution. Thanks! On 11/15/06, Maxim Kulkin <maxim.kulkin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/14/06, Matt White <stockliasteroid-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Maxim, > > > > I used your original render :action => "template.rjs" option, and that > > works fine. I''m on Edge, but when I try render :template => "template" or > > render :template => "template.rjs " assert_existence_of_template_file > > throws a MissingTemplate error because it''s looking for the wrong file type > > (rhtml). > > > Difference between render :action => and render :template => is that > template is searched relative to TEMPLATE ROOT (which is > RAILS_ROOT/app/views by default). So to use render :template => you should > supply proper path, e.g. render :template => ''mycontroller/template.rjs''. > > Hope that helps. > > > > >-- Thermal Creative http://blog.thermalcreative.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 -~----------~----~----~----~------~----~------~--~---