我的目標是使用相同的控制器調用html.erb和js.erb文件,但它只調用我的html文件。
我的js沒有被調用。
控制器/ categories_controller.rbRuby on Rails - 同時調用html.erb和js.erb
def index
respond_to do |format|
format.html
format.js
end
@categories = Category.order('name ASC')
@category = params[:category]
end
視圖/類別/ index.html.erb
<% @categories.each do |c| %>
<%= link_to c.name, show_category_path(category: c.id), :id => "btn-filter#{c.id}" %>
<% end %>
視圖/類別/ index.js.erb的(該問題是在這裏,該文件不叫)
alert("test");
$("#btn-filter<%[email protected]%>").attr("class","active");
[here](http://stackoverflow.com/questions/9492362/rails-how-does-the-respond-to-block-work)你可以找到澄清的討論。 – rfellons
另一個有趣的討論[這裏](http://stackoverflow.com/questions/43558477/render-different-show-pages-with-category-in-ruby-on-rails) – rfellons