there is a controller action>def loop_type_action > book = Book.find_one_book_that_left #find a book haven''t read > book.update_attribute("is_read",true) #mark it as read > @result = book.read #fetch book content >endWhen this action is called,I want the @result be shown on the browser, then AFTER the @result is shown, I want it call this action again and do the same thing to show next book. I''ve tried redirect_to method, but it won''t give the chance to show anything on the browser before it redirect the action. Any idea to do this? -- 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 -~----------~----~----~----~------~----~------~--~---
Why don''t you call all of the unread books up into an array and then use javascript to walk through the array, either timed or upon a button click in the front end. You could even use AJAX to post the update_attributes to the server after the book has been read, rather than making tons of database calls, you could make 1. Cam On Apr 23, 7:06 am, Nanyang Zhan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> there is a controller action > > >def loop_type_action > > book = Book.find_one_book_that_left #find a book haven''t read > > book.update_attribute("is_read",true) #mark it as read > > @result = book.read #fetch book content > >end > > When this action is called,I want the @result be shown on the browser, > then AFTER the @result is shown, I want it call this action again and do > the same thing to show next book. > > I''ve tried redirect_to method, but it won''t give the chance to show > anything on the browser before it redirect the action. > > Any idea to do this? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Nanyang Zhan
2007-Apr-23 08:25 UTC
Re: call action, render it, then redirect back to itself
cammo wrote:> Why don''t you call all of the unread books up into an array and then > use javascript to walk through the array, either timed or upon a > button click in the front end. You could even use AJAX to post the > update_attributes to the server after the book has been read, rather > than making tons of database calls, you could make 1.thanks cam. in fact, the read book action just a example to explain my need. I use it because its simplicity. In really action, that will be taken into use, will include more Model operations. What I really need is a loop action (as I said, may including many Model operations), with realtime(or at lease, kind of "live"), front end view (showing which loop is going on, how many loops left, is an error happen? what massage it gives if any error does happen...) so, your idea is really good when I want a read book app, but it seems not fix my current app. Tons of database calls are needed. -- 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 -~----------~----~----~----~------~----~------~--~---
I would achieve this by calling def loop_type_action book = Book.find_one_book_that_left #find a book haven''t read book.update_attribute("is_read",true) #mark it as read @result = book.read #fetch book content headers["Refresh"] = "5; URL=" + url_for(:action => "loop_type_action") end This will cause the page to refresh every 5 seconds, calling loop_type_action each time. You can change the number to the time you desire. You can also use expires_now() in the controller action and putting link_to(:action => "loop_type_action") in the view on an element like the book title or cover (in this example). Every time the user clicks, the page should refresh. expires_now causes it to not be cached. I can also think of some Javascript things you could do to refresh the page only when certain conditions are true. You could also use Rails'' script.aculo.us support to provide graphical feedback while the action reloads. See <http://api.rubyonrails.org/classes/ActionView/Helpers/ ScriptaculousHelper.html#M000515>. Cheers, Ross On Apr 23, 4:25 am, Nanyang Zhan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> cammo wrote: > > Why don''t you call all of the unread books up into an array and then > > use javascript to walk through the array, either timed or upon a > > button click in the front end. You could even use AJAX to post the > > update_attributes to the server after the book has been read, rather > > than making tons of database calls, you could make 1. > > thanks cam. > > in fact, the read book action just a example to explain my need. I use > it because its simplicity. In really action, that will be taken into > use, will include more Model operations. > > What I really need is a loop action (as I said, may including many Model > operations), with realtime(or at lease, kind of "live"), front end view > (showing > which loop is going on, how many loops left, is an error happen? what > massage it gives if any error does happen...) > > so, your idea is really good when I want a read book app, but it seems > not fix my current app. Tons of database calls are needed. > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Nanyang Zhan
2007-Apr-23 19:55 UTC
Re: call action, render it, then redirect back to itself
RossW wrote:> I can also think of some Javascript things you could do to refresh the > page only when certain conditions are true.Thanks RossW, I have just done a javascript test. I put this code at the up part of the view page, <script type="text/javascript"> <!-- function delayer(){ window.location = "/books;read?current_book=<%=@current_book%>?book_left=<%= @book_left%>?start_time=<%=@start_time%>" } //--> </script> <%= @book_content%> and this code at the bottom of the view: <script type="text/javascript"> <!-- setTimeout(''delayer()'', 3000) //--> </script> It works fine. But I still have a question: when exactly will the delayer function be called? 3 seconds after the page is open or 3 seconds after the controller method have been taken and @book_content is shown? -- 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 -~----------~----~----~----~------~----~------~--~---