Hi, I am using the link_to_remote helper to call an action using and XMLHttp request. The action method has a call to render another action if a condition is met: if session[:prebooking].start_date != nil render :action => ''check_rate'' end the condition is being met, i.e. I checked that ''session[:prebooking].start_date != nil'' is in fact true, but program fails to render ''check_rate''. Is this because I am using a HTTP post request to call the action? How do I get ''check_rate'' to render if the condition is met? Thank you! Sam -- 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 -~----------~----~----~----~------~----~------~--~---
> > if session[:prebooking].start_date != nil > render :action => ''check_rate'' > endJust checking - you dont have code under the if statement that renders something else? Only ask because I''ve done something similar before now ;0) Luke -- 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 -~----------~----~----~----~------~----~------~--~---
Luke Pearce wrote:>> >> if session[:prebooking].start_date != nil >> render :action => ''check_rate'' >> end > > Just checking - you dont have code under the if statement that renders > something else? > > Only ask because I''ve done something similar before now ;0) > > LukeNo, this is the end of the method: if session[:prebooking].start_date != nil render :action => ''check_rate'' end end Sam -- 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 -~----------~----~----~----~------~----~------~--~---
Sam Woodard wrote:> Luke Pearce wrote: >>> >>> if session[:prebooking].start_date != nil >>> render :action => ''check_rate'' >>> end >> >> Just checking - you dont have code under the if statement that renders >> something else? >> >> Only ask because I''ve done something similar before now ;0) >> >> Luke > > No, this is the end of the method: > > if session[:prebooking].start_date != nil > render :action => ''check_rate'' > end > end > > SamTake your render call out of the "if" block and see what happens. If it renders what you expect, the bug is in your condition, not the rendering. -- 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Sam Woodard wrote: >> Luke Pearce wrote: >>>> >>>> if session[:prebooking].start_date != nil >>>> render :action => ''check_rate'' >>>> end >>> >>> Just checking - you dont have code under the if statement that renders >>> something else? >>> >>> Only ask because I''ve done something similar before now ;0) >>> >>> Luke >> >> No, this is the end of the method: >> >> if session[:prebooking].start_date != nil >> render :action => ''check_rate'' >> end >> end >> >> Sam > > Take your render call out of the "if" block and see what happens. If it > renders what you expect, the bug is in your condition, not the > rendering.I already tested the condition by doing this: if session[:prebooking].start_date != nil puts "condition met" render :action => ''check_rate'' end This puts "condition met" at the console. Sam -- 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 -~----------~----~----~----~------~----~------~--~---
Sam Woodard wrote:> Alex Wayne wrote: >> Sam Woodard wrote: >> Take your render call out of the "if" block and see what happens. If it >> renders what you expect, the bug is in your condition, not the >> rendering. > > I already tested the condition by doing this: > > if session[:prebooking].start_date != nil > puts "condition met" > render :action => ''check_rate'' > end > > This puts "condition met" at the console.I think what he means is that maybe the condition is good, but the render is bad. For example, do you have an :update in your link_to_remote? Maybe the rendering is just getting thrown away. Jake -- 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 -~----------~----~----~----~------~----~------~--~---
Sam Woodard wrote:> I am using the link_to_remote helper to call an action using and XMLHttp > request. The action method has a call to render another action if a > condition is met: > > if session[:prebooking].start_date != nil > render :action => ''check_rate'' > end > > the condition is being met, i.e. I checked that > ''session[:prebooking].start_date != nil'' is in fact true, but program > fails to render ''check_rate''.To do a normal render from a xhr request you have to use a RJS redirect: render :update do |page| if session[:prebooking].start_date.nil? # normal RJS else page.redirect_to :action => :check_rate end end -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jake Janovetz wrote:> Sam Woodard wrote: >> Alex Wayne wrote: >>> Sam Woodard wrote: >>> Take your render call out of the "if" block and see what happens. If it >>> renders what you expect, the bug is in your condition, not the >>> rendering. >> >> I already tested the condition by doing this: >> >> if session[:prebooking].start_date != nil >> puts "condition met" >> render :action => ''check_rate'' >> end >> >> This puts "condition met" at the console. > > I think what he means is that maybe the condition is good, but the > render is bad. For example, do you have an :update in your > link_to_remote? Maybe the rendering is just getting thrown away. > > JakeI don''t have an :update. What should I store in this value because I don''t want to update a partial, I want to render a different action if this specific condition is met. Sam -- 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 -~----------~----~----~----~------~----~------~--~---
Since you don''t have an :update, the browser assumes what you have rendered is javascript (btw I find FireBug absolutely essential for doing this kind of thing) You can''t quite do what you want to do with link to remote. With link to remote you either : -generate some javascript (via rjs or render :update) that is run when the response is returned to the browser - include an :update parameter, the content of the specified element on the page is replaced with whatever you render There isn''t a specific replace the whole page - although you could of course pass an :update that effectively does that. Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Here''s what I came up with: <%= link_to_remote @current_two_months[0][days_in_first_week].date.mday, :url => {:action => ''start_date'', :id => day}, :update => "month" if @current_two_months[0][days_in_first_week].date.wday == i && session[:prebooking].end_date == nil%> <%= link_to @current_two_months[0][days_in_first_week].date.mday, {:action => ''check_rate'', :id => day} if @current_two_months[0][days_in_first_week].date.wday == i && session[:prebooking].end_date != nil%> This way a XMLHttp post link is created if the user has not already selected an end_date for their vacation stay. However, if the user has already selected the end_date using javascript on the second calendar, the application will move forward in the process using a standard get link and vise versa. By the way, after updating the session data, with either the start_date or end date, the link_to_remote method is set to update the months partial so that the the AJAX links are replaced with get requests. Best Regards, Sam Woodard -- 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 -~----------~----~----~----~------~----~------~--~---
Sam Woodard wrote:> Here''s what I came up with: > > <%= link_to_remote @current_two_months[0][days_in_first_week].date.mday, > :url => {:action => ''start_date'', :id => day}, :update => "month" if > @current_two_months[0][days_in_first_week].date.wday == i && > session[:prebooking].end_date == nil%> > > <%= link_to @current_two_months[0][days_in_first_week].date.mday, > {:action => ''check_rate'', :id => day} if > @current_two_months[0][days_in_first_week].date.wday == i && > session[:prebooking].end_date != nil%> > > This way a XMLHttp post link is created if the user has not already > selected an end_date for their vacation stay. However, if the user has > already selected the end_date using javascript on the second calendar, > the application will move forward in the process using a standard get > link and vise versa. By the way, after updating the session data, with > either the start_date or end date, the link_to_remote method is set to > update the months partial so that the the AJAX links are replaced with > get requests. > > Best Regards, > > Sam WoodardNew, improved and tested: <%=if !session[:prebooking] || !session[:prebooking].end_date link_to_remote day.date.mday, :url => {:action => ''start_date'', :id => day}, :update => "months" else link_to day.date.mday, {:action => ''check_rate'', :id => day} end%> -- 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 -~----------~----~----~----~------~----~------~--~---