ruby on rails - How to inject logic into javascript in HAML? -



ruby on rails - How to inject logic into javascript in HAML? -

i'm attempting add together mercury editor , while modifying layout it, suggests add together javascript view layout. next won't quite work, expresses gist of i'm attempting accomplish. you'll want @ section within :javascript filter, on downwards add together - begin if statement mean:

... %body{ :class => "#{controller_name} #{action_name}" } :javascript var saveurl = null; // set url want save given page to. var options = { savestyle: null, // 'form', or 'json' (default json) savemethod: null, // 'post', or 'put', (create, vs. update -- default post) visible: null // if interface should start visible or not (default true) }; //<!-- mix in configurations provided through rails.application.config.mercury_config --> - if rails.application.config.respond_to?(:mercury_config) jquery.extend(mercury.config, = rails.application.config.mercury_config.to_json.html_safe ); - end //<!-- mix in options pageeditor provided through rails.application.config.mercury_page_editor_config --> - if rails.application.config.respond_to?(:mercury_page_editor_config) jquery.extend(options, = rails.application.config.mercury_page_editor_config.to_json.html_safe ); - end //<!-- instantiate pageeditor --> new mercury.pageeditor(saveurl, options); ...

could please provide illustration of how properly?

you extract logic helper methods , interpolate results. take look.

# page_helper.rb def mercury_config if rails.application.config.respond_to?(:mercury_config) "jquery.extend(mercury.config, #{rails.application.config.mercury_config.to_json.html_safe} );" end end def mercury_page_editor_config if rails.application.config.respond_to?(:mercury_page_editor_config) "jquery.extend(options, #{rails.application.config.mercury_page_editor_config.to_json.html_safe} );" end end # your_view.html.haml :javascript var saveurl = null; // set url want save given page to. var options = { savestyle: null, // 'form', or 'json' (default json) savemethod: null, // 'post', or 'put', (create, vs. update -- default post) visible: null // if interface should start visible or not (default true) }; //<!-- mix in configurations provided through rails.application.config.mercury_config --> #{mercury_config} //<!-- mix in options pageeditor provided through rails.application.config.mercury_page_editor_config --> #{mercury_page_editor_config} //<!-- instantiate pageeditor --> new mercury.pageeditor(saveurl, options);

ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 haml

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -