Hi, I want to create some reports on my app that are stored. So it is not a big deal to create a view where my report is shown out of some existing activerecords. But how can I save what I see? Meaning save the whole page as report in the database. I thought the easiest way is to store the whole page in a long string with html markup. So I can easily render that value later with ''raw'' method. An example: store this as activerecord: <p>This is some text</p> call that in a later view for showing the report: <%= raw Report.find(12).text %> Is that the best approach or is there another one? If it is the best approach, is there a way to get the html code of the recent page to store that in an activerecord. Sebastian -- 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.
Similar question: Is it possible to store the output of a rendered partial as html? Sebastian On May 25, 2:15 pm, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi, > > I want to create some reports on my app that are stored. So it is not > a big deal to create a view where my report is shown out of some > existing activerecords. > > But how can I save what I see? Meaning save the whole page as report > in the database. I thought the easiest way is to store the whole page > in a long string with html markup. So I can easily render that value > later with ''raw'' method. > > An example: > > store this as activerecord: > <p>This is some text</p> > > call that in a later view for showing the report: > <%= raw Report.find(12).text %> > > Is that the best approach or is there another one? If it is the best > approach, is there a way to get the html code of the recent page to > store that in an activerecord. > > Sebastian-- 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.
As long as it isn''t too large for a text column in your DB, sure. Walter On May 25, 2011, at 9:28 AM, Sebastian wrote:> Similar question: > > Is it possible to store the output of a rendered partial as html? > > Sebastian > > On May 25, 2:15 pm, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> Hi, >> >> I want to create some reports on my app that are stored. So it is not >> a big deal to create a view where my report is shown out of some >> existing activerecords. >> >> But how can I save what I see? Meaning save the whole page as report >> in the database. I thought the easiest way is to store the whole page >> in a long string with html markup. So I can easily render that value >> later with ''raw'' method. >> >> An example: >> >> store this as activerecord: >> <p>This is some text</p> >> >> call that in a later view for showing the report: >> <%= raw Report.find(12).text %> >> >> Is that the best approach or is there another one? If it is the best >> approach, is there a way to get the html code of the recent page to >> store that in an activerecord. >> >> Sebastian > > -- > 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 > . > 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.
On Wed, May 25, 2011 at 8:15 PM, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote:> Hi, > > I want to create some reports on my app that are stored. So it is not > a big deal to create a view where my report is shown out of some > existing activerecords. > > But how can I save what I see? Meaning save the whole page as report > in the database. I thought the easiest way is to store the whole page > in a long string with html markup. So I can easily render that value > later with ''raw'' method. > > An example: > > store this as activerecord: > <p>This is some text</p> > > call that in a later view for showing the report: > <%= raw Report.find(12).text %> > > Is that the best approach or is there another one? If it is the best > approach, is there a way to get the html code of the recent page to > store that in an activerecord. > >Just a quick reply. If you''re going with the save to db approach, I think you might want to look at the render_to_string method.> Sebastian > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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.
That would work. You may want to consider if it is just HTML text, or if the reports reference any images, video, additional files..., and whether you want to keep them too. If you have a complex HTML page, and you want to use the DB approach (instead of just saving the file directly in disk and keeping the path in the DB), you may want to take a look to MHTML, parse the HTML and encode all the page elements using that format. C On Wed, May 25, 2011 at 8:15 AM, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote:> Hi, > > I want to create some reports on my app that are stored. So it is not > a big deal to create a view where my report is shown out of some > existing activerecords. > > But how can I save what I see? Meaning save the whole page as report > in the database. I thought the easiest way is to store the whole page > in a long string with html markup. So I can easily render that value > later with ''raw'' method. > > An example: > > store this as activerecord: > <p>This is some text</p> > > call that in a later view for showing the report: > <%= raw Report.find(12).text %> > > Is that the best approach or is there another one? If it is the best > approach, is there a way to get the html code of the recent page to > store that in an activerecord. > > Sebastian > > -- > 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.
On 25 May 2011 13:15, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi, > > I want to create some reports on my app that are stored. So it is not > a big deal to create a view where my report is shown out of some > existing activerecords. > > But how can I save what I see? Meaning save the whole page as report > in the database. I thought the easiest way is to store the whole page > in a long string with html markup. So I can easily render that value > later with ''raw'' method.Have you considered using page caching instead? http://guides.rubyonrails.org/caching_with_rails.html Colin -- 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.
Thank you all for your answers. @Jim Ruther Nill: render_to_string sounds exactly like what I need, but I get an error of ''undefined method''. I am using this code in view: <%= render_to_string(:partial => "shared/compare", :collection => @changedfamilies) %> @Colin Law: Cache is only temporarily. I need to save the report permanently, so cache is no option. @C.A.C.D: I only have html with colored text and tables on it. So your approach with MHTML is only for complex html''s, right? Kind regards, Sebastian On May 25, 8:56 pm, "C. A. C. D." <cdup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That would work. You may want to consider if it is just HTML text, or if the > reports reference any images, video, additional files..., and whether you > want to keep them too. > > If you have a complex HTML page, and you want to use the DB approach > (instead of just saving the file directly in disk and keeping the path in > the DB), you may want to take a look to MHTML, parse the HTML and encode all > the page elements using that format. > > C > > On Wed, May 25, 2011 at 8:15 AM, Sebastian > <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote: > > > > > > > > > Hi, > > > I want to create some reports on my app that are stored. So it is not > > a big deal to create a view where my report is shown out of some > > existing activerecords. > > > But how can I save what I see? Meaning save the whole page as report > > in the database. I thought the easiest way is to store the whole page > > in a long string with html markup. So I can easily render that value > > later with ''raw'' method. > > > An example: > > > store this as activerecord: > > <p>This is some text</p> > > > call that in a later view for showing the report: > > <%= raw Report.find(12).text %> > > > Is that the best approach or is there another one? If it is the best > > approach, is there a way to get the html code of the recent page to > > store that in an activerecord. > > > Sebastian > > > -- > > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2011 08:51, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Thank you all for your answers. > ... > @Colin Law: Cache is only temporarily. I need to save the report > permanently, so cache is no option.A page cache can be as permanent as you like. It is up to you when you expire it. If you never expire it then it will be permanent. By doing it yourself you are just re-inventing the wheel. The work has already been done for you by Rails developers. Colin -- 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.
render_to_string worked perfectly! I just have to this in the controller and not in the view. Controller: @reportstring = render_to_string(:partial => "shared/ compare", :collection => @changedfamilies) Then I can save the @reportstring in my database and call the whole view wherever I need it! Thank you! On May 26, 10:17 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 May 2011 08:51, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > Thank you all for your answers. > > ... > > @Colin Law: Cache is only temporarily. I need to save the report > > permanently, so cache is no option. > > A page cache can be as permanent as you like. It is up to you when > you expire it. If you never expire it then it will be permanent. By > doing it yourself you are just re-inventing the wheel. The work has > already been done for you by Rails developers. > > Colin-- 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.
Sebastian wrote in post #1001166:> render_to_string worked perfectly! > > I just have to this in the controller and not in the view. > > Controller: > > @reportstring = render_to_string(:partial => "shared/ > compare", :collection => @changedfamilies) > > Then I can save the @reportstring in my database and call the whole > view wherever I need it!Do you need this solution to scale? Fetching that large string from the database is going to be far less efficient than Colin''s suggestion about using page caching. The web server was designed to be highly efficient at serving static HTML content (i.e the cached pages). Using Rails and the database can''t possibly match the performance of Apache or Nginx. -- 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.
OK...I still have a problem: The render_to_string method is only available in controllers and not in models and views!!! My approach was to check with several delayed_job my database entries for changes (compare with external webservice!) and then run a delayed_job for create the report with lower priority afterwards. That is not working because I can''t use render_to_string in a model for the delayed_job. Has anyone an idea how to solve this? Or is it possible to delay a method from another controller? I am so close! If I just call the method on a view the whole page is stored as I want. I only need to do this in a delayed_job...! @Colin Law: I had a look into caching, but I didn''t understand the whole thing, so I think for me it would be easier if my first approach would work. Sebastian On May 26, 11:51 am, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> render_to_string worked perfectly! > > I just have to this in the controller and not in the view. > > Controller: > > @reportstring = render_to_string(:partial => "shared/ > compare", :collection => @changedfamilies) > > Then I can save the @reportstring in my database and call the whole > view wherever I need it! > > Thank you! > > On May 26, 10:17 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > > > On 26 May 2011 08:51, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > Thank you all for your answers. > > > ... > > > @Colin Law: Cache is only temporarily. I need to save the report > > > permanently, so cache is no option. > > > A page cache can be as permanent as you like. It is up to you when > > you expire it. If you never expire it then it will be permanent. By > > doing it yourself you are just re-inventing the wheel. The work has > > already been done for you by Rails developers. > > > Colin-- 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.
SHORT UPDATE: Sorry! Stupid idea! I can of course just move my method into the same controller, so I don''t have to leave it. I have the following in my controller: def checkall ->check all entries for updates<- create_report -> This should just run my method below asynchronously end def create_report ->this creates my report<- end handle_asynchronously :create_report, :priority => 3 On Jun 1, 9:31 am, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> OK...I still have a problem: > > The render_to_string method is only available in controllers and not > in models and views!!! > > My approach was to check with several delayed_job my database entries > for changes (compare with external webservice!) and then run a > delayed_job for create the report with lower priority afterwards. > > That is not working because I can''t use render_to_string in a model > for the delayed_job. > > Has anyone an idea how to solve this? > > Or is it possible to delay a method from another controller? > > I am so close! If I just call the method on a view the whole page is > stored as I want. I only need to do this in a delayed_job...! > > @Colin Law: I had a look into caching, but I didn''t understand the > whole thing, so I think for me it would be easier if my first approach > would work. > > Sebastian > > On May 26, 11:51 am, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > > > render_to_string worked perfectly! > > > I just have to this in the controller and not in the view. > > > Controller: > > > @reportstring = render_to_string(:partial => "shared/ > > compare", :collection => @changedfamilies) > > > Then I can save the @reportstring in my database and call the whole > > view wherever I need it! > > > Thank you! > > > On May 26, 10:17 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > On 26 May 2011 08:51, Sebastian <sebastian.go...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Thank you all for your answers. > > > > ... > > > > @Colin Law: Cache is only temporarily. I need to save the report > > > > permanently, so cache is no option. > > > > A page cache can be as permanent as you like. It is up to you when > > > you expire it. If you never expire it then it will be permanent. By > > > doing it yourself you are just re-inventing the wheel. The work has > > > already been done for you by Rails developers. > > > > Colin-- 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.
On 1 June 2011 08:41, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> SHORT UPDATE: > > Sorry! Stupid idea! I can of course just move my method into the same > controller, so I don''t have to leave it. > > I have the following in my controller: > > def checkall > ->check all entries for updates<- > > create_report -> This should just run my method below > asynchronously > end > > > def create_report > ->this creates my report<- > end > handle_asynchronously :create_report, :priority => 3It all seems a lot more complex than page caching. Colin -- 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.
Top-posted from Android On Jun 1, 2011 9:39 PM, "Colin Law" <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: On 1 June 2011 08:41, Sebastian <sebastian.goldt-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > SHORT UPDATE: > > Sorry! S... It all seems a lot more complex than page caching. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails... -- 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.
I am completely stuck!!! This one is working in my controller, BUT NOT as a delayed_job: def checkall #check all entries for updates as delayed_job create_report #should run my method below asynchronously end def create_report #this creates my report, but not working delayed! end handle_asynchronously :create_report, :priority => 3 So maybe the caching approach is really a better solution ;-) How can I cache the page I need as a delayed_job? I need to complete the ''checkall'' method before creating my report! Sebastian -- 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.
Recently I got my first approach working! I only had to edit the following (this_here)to call my method out of my controller: def checkall #check all entries for updates as delayed_job this_here = MyController.new this_here.create_report #run my method below asynchronously end def create_report #this creates my report, but not working delayed! end handle_asynchronously :create_report, :priority => 3 I don''t know if this is good coding, but it is working! -- 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.