Hi, I want pass a variable(which is not a instance variable) from controller to view in rails application, onclick I am going to controller and fetching data with ajax. Since the page is not reloaded I cant set the variable in cookies. So is there any way to pass a variable(which is not an instance variable) from controler to view? -- 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 https://groups.google.com/groups/opt_out.
On 17 December 2012 08:59, Praveen BK <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, I want pass a variable(which is not a instance variable) from > controller to view in rails application, onclick I am going to > controller and fetching data with ajax. Since the page is not reloaded I > cant set the variable in cookies. So is there any way to pass a > variable(which is not an instance variable) from controler to view?If I understand your question correctly then just define an @variable to store it so @my_variable = something then in the view use @my_variable. 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 https://groups.google.com/groups/opt_out.
Adding @ to a variable doesn make the variable instance variable, its convention that are followed while writing a ruby program, I think... Here I have a variable x = 10, in my controller how can i access it in view without using cookies. -- 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 https://groups.google.com/groups/opt_out.
Adding @ to a variable doesn make the variable instance variable, its convention that are followed while writing a ruby program, I think... Here I have a variable x = 10, in my controller how can i access it in view without using cookies. -- 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 https://groups.google.com/groups/opt_out.
On 18 December 2012 05:10, Praveen BK <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Adding @ to a variable doesn make the variable instance variable, its > convention that are followed while writing a ruby program, I think... > > Here I have a variable x = 10, in my controller how can i access it in > view without using cookies.Don''t call it x, call it @x then you can access it. Why do you not want to do that? 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 https://groups.google.com/groups/opt_out.
Ya, thank you,adding @ to variable made it available in the view. here, I m making HTTP request using ajax, which goes to my controller and executes a method, Now I m getting return value in view. But I have to display it in popup menu. the code for the pop up is $.colorbox({html:"<%= @x %>", width:"35%",height:"400px"}); But this value of @x is not displayed in pop up. -- 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 https://groups.google.com/groups/opt_out.
"$.colorbox({html:"<%= @x %>", width:"35%",height:"400px"}); " Assuming that the line of jquery code is executed client side and operates on the HTML returned from the Ajax request you will not have access to the instance variable. It will have been rendered in the returned HTML on the server. You will either need to parse the value out of the HTML or just return json and access it. -- 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. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/mxFMthQCCn0J. For more options, visit https://groups.google.com/groups/opt_out.