Hi everyone, I have a template called createFile.html.erb which has some ruby code in it. The ruby code pulls information from the database because i''m looping through some records. Is it possible to send all of the information in the createFile.html.erb output to the createFile method in the controller? I''m wanting to save the content of it all to a text file... Or is there an easier way to produce the same outcome? Thanks, McKenzie. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-07 17:40 UTC
Re: Passing information to the controller from view
On 7 Jan 2009, at 17:33, Ryan Mckenzie wrote:> > Hi everyone, > > I have a template called createFile.html.erb which has some ruby > code in > it. The ruby code pulls information from the database because i''m > looping through some records. Is it possible to send all of the > information in the createFile.html.erb output to the createFile method > in the controller? I''m wanting to save the content of it all to a text > file... >render_to_string ? Fred> Or is there an easier way to produce the same outcome? > > Thanks, > McKenzie. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 7 Jan 2009, at 17:33, Ryan Mckenzie wrote: > >> > render_to_string ? > > Fredrender_to_string puts the whole html document in the data including the template, however I only need part of the file. This code might explain it a little better. #demo_controller.rb 1. def createFile 2. render_to_string :layout => false 3. @demo = Demo.find(params[:id]) 4. 5. data = render_to_string 6. 7. f = File.open("#{RAILS_ROOT}/public/demo/demotest.txt", "wb") 8. f.write(data) 9. f.close 10. 11. end #demo/createFile.html.erb 1. ModelTemp { 2. Name "Mod" 3. Halt 0.0 4. DType "Define" 5. FData { 6. Events { 7. <% for event in display_demo_events(@demo) %> 8. Event { 9. Name "<%= event.name -%>" 10. Desc "<%= event.description -%>" 11. Constant {FRate="<%= event.f_rate -%>"} 12. } 13. <% end %> 14. } 15. Outputs { 16. <% for deviation in display_demo_events(@demo) %> 17. Deviation { 18. Name "<%= deviation.output_class -%>" 19. "<%= deviation.description -%>" 20. } 21. <% end %> 22. } 23. } 24. } -- 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 Jan 7, 2009, at 6:45 PM, Ryan Mckenzie wrote:> > Frederick Cheung wrote: >> On 7 Jan 2009, at 17:33, Ryan Mckenzie wrote: >> >>> >> render_to_string ? >> >> Fred > > render_to_string puts the whole html document in the data including > the > template, however I only need part of the file. This code might > explain > it a little better. > > #demo_controller.rb > 1. def createFile > 2. render_to_string :layout => falserender here...> > 3. @demo = Demo.find(params[:id]) > 4. > 5. data = render_to_string...and here??? (without giving :layout => false)> > 6. > 7. f = File.open("#{RAILS_ROOT}/public/demo/demotest.txt", "wb") > 8. f.write(data) > 9. f.close > 10. > 11. end > > #demo/createFile.html.erb > 1. ModelTemp { > 2. Name "Mod" > 3. Halt 0.0 > 4. DType "Define" > 5. FData { > 6. Events { > 7. <% for event in display_demo_events(@demo) %> > 8. Event { > 9. Name "<%= event.name -%>" > 10. Desc "<%= event.description -%>" > 11. Constant {FRate="<%= event.f_rate -%>"} > 12. } > 13. <% end %> > 14. } > 15. Outputs { > 16. <% for deviation in display_demo_events(@demo) %> > 17. Deviation { > 18. Name "<%= deviation.output_class -%>" > 19. "<%= deviation.description -%>" > 20. } > 21. <% end %> > 22. } > 23. } > 24. } > > -- > 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 -~----------~----~----~----~------~----~------~--~---
In your controller, you just need data = render_to_string({:action => ''create.html.erb'', :layout=>false}) I''m doing a PDF (using HTMLDOC) that way. Works awesome. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> In your controller, you just need > > data = render_to_string({:action => ''create.html.erb'', > :layout=>false}) > > I''m doing a PDF (using HTMLDOC) that way. Works awesome.Hi Brian, that works a treat thanks. I''m also trying to output some information to a pdf. Have you got an email address I can contact you at? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
bphogan at gmail dot com On Thu, Jan 8, 2009 at 8:47 AM, Ryan Mckenzie <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Brian Hogan wrote: >> In your controller, you just need >> >> data = render_to_string({:action => ''create.html.erb'', >> :layout=>false}) >> >> I''m doing a PDF (using HTMLDOC) that way. Works awesome. > > Hi Brian, that works a treat thanks. I''m also trying to output some > information to a pdf. Have you got an email address I can contact you > at? > > Thanks > -- > 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 -~----------~----~----~----~------~----~------~--~---