如何获取我的js.erb文件?
我的js.erb
文件不会出现在Rails 3.1.2中,这让我很困惑。 我将它包含在app/views/items
。 我有这个:
respond_to do |format| format.html { render :action => :index } format.js {render :content_type => 'text/javascript' } end
并且它的名字正确。 我尝试了不同的名称组合,但我甚至不理解如何包含js.erb,因为它不在我的源代码中。 我发出alert('hello');
在js.erb
,它不会运行。
如果js.erb
与控制器操作同名, request.xhr?
js.erb
request.xhr?
如果是,那么它会自动渲染js.erb
。 在respond_to
块中,删除format.js
之后的代码,使其看起来像:
respond_to do |format| format.html { render :action => :index } format.js end
只要确保激活它的链接有remote => true
,例如link_to 'Some action', some_action_path, :remote => true
。