Is there anyway I can render a view outside of a controller ? I''m using BackgroundRB , and I''d like to use render_to_string in a worker to render some html that will update a facebook profile. These are perodic updates and so these must happen in a scheduled process rather than in real time from a controller. The only other option I can think of is just to create an action that my worker calls with the appropriate values and ensure that the request is only allowed locally. I''d prefer not to do this as it may tie up some of my web server processes.. -- 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 Wed, Mar 26, 2008 at 6:43 AM, Dave Fumberger <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Is there anyway I can render a view outside of a controller ? > > I''m using BackgroundRB , and I''d like to use render_to_string in a > worker to render some html that will update a facebook profile. These > are perodic updates and so these must happen in a scheduled process > rather than in real time from a controller. > > The only other option I can think of is just to create an action that my > worker calls with the appropriate values and ensure that the request is > only allowed locally. I''d prefer not to do this as it may tie up some of > my web server processes.. > --I haven''t tried myself,but you have access to entire rails environment in your worker, hence you can use render_to_string easily. Also, You probably want the rendered result to be saved in database or result hash. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.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 -~----------~----~----~----~------~----~------~--~---
Hemant Kumar wrote:> On Wed, Mar 26, 2008 at 6:43 AM, Dave Fumberger > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> only allowed locally. I''d prefer not to do this as it may tie up some of >> my web server processes.. >> -- > > I haven''t tried myself,but you have access to entire rails environment > in your worker, hence you can use render_to_string easily. > Also, You probably want the rendered result to be saved in database or > result hash. > > -- > Let them talk of their oriental summer climes of everlasting > conservatories; give me the privilege of making my own summer with my > own coals. > > http://gnufied.orgYes I''ve got access to the environment but as render_to_string is defined in ActionController I have to instantiate this either from base or an existing controller .. when I do this it gives me an from render_to_string when it calls ''erase_render_results'': def erase_render_results #:nodoc: response.body = nil @performed_render = false end response is nil and so it blows up there... It''s easy to replicate, just try calling the action of another controller (that calls render_to_string) inside a controller. -- 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 -~----------~----~----~----~------~----~------~--~---
blasterpal wrote:> I don''t know if this is something you have considered, but using wget > in cron locally might be another option. > >Yeah, that''s what I was implying in my first post "The only other option I can think of is just to create an action that my worker calls with the appropriate values and ensure that the request is only allowed locally." Which is what I''ve done for the mean time. Using BackgroundRB to schedule a worker which uses Net::HTTP to do a get request to an action on my application. I decided to keep with backgroundrb to do this (as opposed to cron and wget) as I"ve got other processes which happen so this keeps things consistent. -- 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 this may not be a very elegant solution(or may not even be viable) but you can probably do this def get_binding binding end File.open("#{RAILS_ROOT}/app/views/<path>/<filename>", "r"){|f| template=f.readlines.to_s } rhtml = ERB.new(template) str=rhtml.result(self.get_binding) out.write str #your rhtml rendered as html instead of using render_to_string to render some html On Thu, Mar 27, 2008 at 4:04 AM, Dave Fumberger < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > blasterpal wrote: > > I don''t know if this is something you have considered, but using wget > > in cron locally might be another option. > > > > > > Yeah, that''s what I was implying in my first post > > "The only other option I can think of is just to create an action that > my > worker calls with the appropriate values and ensure that the request is > only allowed locally." > > Which is what I''ve done for the mean time. Using BackgroundRB to > schedule a worker which uses Net::HTTP to do a get request to an action > on my application. I decided to keep with backgroundrb to do this (as > opposed to cron and wget) as I"ve got other processes which happen so > this keeps things consistent. > -- > 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 -~----------~----~----~----~------~----~------~--~---