开发者

Change a regexp in application.js from rails

开发者 https://www.devze.com 2022-12-29 20:55 出处:网络
I wand to change the regular expression in my applicat开发者_如何学编程ion.js file from within a rails controller.

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 %>);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号