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? -- Posted via http://www.ruby-forum.com/.
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 <script type="text/javascript" src="/controller/action_with_rjs_file" /> That should work, I''ve done that before. j`ey http://www.eachmapinject.com -- Posted via http://www.ruby-forum.com/.
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. -- Posted via http://www.ruby-forum.com/.