mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Oct-20 14:48 UTC
How can I render a template outside of a controller in Rails 3?
Hi All, I can''t seem to render a template outside of a controller in my Rails 3 application. The googling I''ve done has been helpful, and I eventually found some useful info at http://www.swombat.com/rails-rendering-templates-outside-of-a-contro. However, this seems to be broken in Rails 3. Does anyone have any ideas how I can fix this method or perhaps know of a better approach? My method: def render_erb(template_path, params) view = ActionView::Base.new(ActionController::Base.view_paths, {}) class << view include ApplicationHelper end view.render(:file => "#{template_path}.html.erb", :locals => params) end The error: ActionView::Template::Error: ActionView::Template::Error from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'' from /Users/mikegerstenblatt/Desktop/bluetrain/lib/test.html.erb:17:in `_lib_test_html_erb__366962844_2173671680_68830'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `send'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `render'' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:54:in `instrument'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:127:in `render'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:59:in `_render_template'' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:56:in `_render_template'' from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:26:in `render'' from /Users/mikegerstenblatt/Desktop/bluetrain/app/models/generated_website.rb:45:in `render_erb'' from (irb):2 Any help would be greatly appreciated. Thanks, Mike -- 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.
Marnen Laibow-Koser
2010-Oct-20 15:13 UTC
Re: How can I render a template outside of a controller in Rails 3?
mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #955787:> Hi All, > > I can''t seem to render a template outside of a controller in my Rails 3 > application.[...] Why would you ever want to? That''s a sure sign that you''re trying to break MVC. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.
mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Oct-20 15:20 UTC
Re: Re: How can I render a template outside of a controller in Rails 3?
I''m aware of breaking the MVC paradigm, however I''m trying to generate a json file used later by an application. On Wed, Oct 20, 2010 at 11:13 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #955787: > > Hi All, > > > > I can''t seem to render a template outside of a controller in my Rails 3 > > application. > [...] > > Why would you ever want to? That''s a sure sign that you''re trying to > break MVC. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
Marnen Laibow-Koser
2010-Oct-20 15:30 UTC
Re: Re: How can I render a template outside of a controller in Rails 3?
Please quote when replying. mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #955803:> I''m aware of breaking the MVC paradigm,Again: don''t do that. There is almost never an actual need to do so.> however I''m trying to generate a > json file used later by an application.Why do you need a JSON file "used later"? What are you trying to achieve? If you need to, then I recommend doing this with a Rake task or script/runner script that works with the Rails MVC architecture rather than against it. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.
mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Oct-20 16:13 UTC
Re: Re: Re: How can I render a template outside of a controller in Rails 3?
>Why do you need a JSON file "used later"? What are you trying to >achieve?I''m generting static html content to be used outside of a rails application. On Wed, Oct 20, 2010 at 11:30 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Please quote when replying. > > mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #955803: > > I''m aware of breaking the MVC paradigm, > > Again: don''t do that. There is almost never an actual need to do so. > > > however I''m trying to generate a > > json file used later by an application. > > Why do you need a JSON file "used later"? What are you trying to > achieve? > > If you need to, then I recommend doing this with a Rake task or > script/runner script that works with the Rails MVC architecture rather > than against it. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
Marnen Laibow-Koser
2010-Oct-20 16:23 UTC
Re: Re: Re: How can I render a template outside of a controller in Rails 3?
mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #955827:>>Why do you need a JSON file "used later"? What are you trying to >>achieve? > > I''m generting static html content to be used outside of a rails > application.OK, now I''m confused. Are you generating HTML or JSON? Is this sort of a data export feature? What''s the workflow like? I''m trying to figure out the best place to put this in a Rails context. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.
Philip Hallstrom
2010-Oct-20 16:28 UTC
Re: How can I render a template outside of a controller in Rails 3?
On Oct 20, 2010, at 7:48 AM, mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hi All, > > I can''t seem to render a template outside of a controller in my Rails 3 application. The googling I''ve done has been helpful, and I eventually found some useful info at http://www.swombat.com/rails-rendering-templates-outside-of-a-contro. However, this seems to be broken in Rails 3. Does anyone have any ideas how I can fix this method or perhaps know of a better approach?Based on your other emails it seems you want this file to be saved for some 3rd-party use later on. Why not just.... curl ''http://yourdomain.com/path/to/view'' > saved.html If you''re going outside of Rails, make life easy and go all the 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-/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.
mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Oct-20 16:50 UTC
Re: How can I render a template outside of a controller in Rails 3?
Great idea Phillip. Is there a way I can call curl from the rails app and save the output to a designated area within the app directory? On Wed, Oct 20, 2010 at 12:28 PM, Philip Hallstrom <philip-LSG90OXdqQE@public.gmane.org> wrote:> > On Oct 20, 2010, at 7:48 AM, mgerstenblatt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > Hi All, > > I can''t seem to render a template outside of a controller in my Rails 3 > application. The googling I''ve done has been helpful, and I eventually found > some useful info at > http://www.swombat.com/rails-rendering-templates-outside-of-a-contro. > However, this seems to be broken in Rails 3. Does anyone have any ideas how > I can fix this method or perhaps know of a better approach? > > > Based on your other emails it seems you want this file to be saved for some > 3rd-party use later on. > > Why not just.... curl ''http://yourdomain.com/path/to/view'' > saved.html > > If you''re going outside of Rails, make life easy and go all the 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.