Change a regexp in application.js from rails
I wand to change the regular expression in my applicat开发者_如何学编程ion.js file from within a rails controller.
Is that possible?Yes it is possible. You can use your Routes file to define it as a an action and then just use ERB to render it. Though it's much better if you can avoid it.
routes.rb
map.myjs '/application.js', :controller => 'my_js_controller', :action => :show
my_js_controller.rb
def show
end
my_js_controller/show.js.erb
$('awesome jquery code').match(<%= render_my_regex_here %>);
精彩评论