In my application I have a button that will open a popup after clicking, in my application_controller, the button is define like this,
{:text => 'Info', :path => Proc.new{ |x| info},
:html => { :id => 'info' }}
and and in application_helper I have a function that will turn that hash to button. I define the info you see in the Proc in application_controller as below:
def self.info
if some_conditions
"javascript: popUpInfoCenter('an_url'); return false;"
else
"javascript: popUpInfoCenter('other_url');return false;"
end
end
the problem I have is after clicking the button, a new popup is opened, which is the desire behavior. However the page that contains that button will render as a blank page with the word "false". I want the page to stay where it was before after click the button. I try to use:
view_context.link_to_function "javascript: popUpInfoCenter('an_url'); return false;"
But both the view_context and link_to_function both die in rail 3.2.14. So if you think there is better way to do this, please show me.
P.S: this is all the files I am able to modify.
Bottom line is that hard-coding JS into a Rails controller goes against convention, and if you want your code to run efficiently, you need to ensure you only deploy each file to do what it needs
Ajax
From the looks of it, I think you need to look at Ajax
Ajax basically allows you to send a request to a URL (controller action), and process the returned value. The syntax is as follows:
Code
You want to load a form based on a variable
I would therefore send the variable through the "data" config of the Ajax request to the action. This will allow us to respond with whatever we need to process that request, which we can use the
respond_tofeature in Rails