开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜