Using RJS in views without ajax


#1

Hi!

I can use RJS in views like this (without using ajax):

<%=link_to_function(“switch fields”,
update_page do |page|
page.insert_html :before, ‘date’, date_select(‘exhibition’, ‘date’)
page.remove ‘date’
end) %>

Is there a way to move this RJS code into a function to separate file?
.js files are not parsed as rjs so it won’t work. Can i just include
.rjs file like ordinary .js file?


#2

szymek wrote:

Hi!

I can use RJS in views like this (without using ajax):

<%=link_to_function(“switch fields”,
update_page do |page|
page.insert_html :before, ‘date’, date_select(‘exhibition’, ‘date’)
page.remove ‘date’
end) %>

Is there a way to move this RJS code into a function to separate file?
.js files are not parsed as rjs so it won’t work. Can i just include
.rjs file like ordinary .js file?

You can include the action with the same name as the RJS, ie

That should work, I've done that before. j`ey http://www.eachmapinject.com

#3

Thanks.

But this way this action will be executed when the page is loaded. Can i
somehow execute this action on demand using link_to_function?

I could probably create helpers for rjs link_to_function calls, it won’t
be perfect, but it should work and the code in views will be a bit
cleaner.