在我的个人资料/ index.html.haml中, 我有
:javascript
$(document).ready(function(){
$('#clickablething').click(function() {
$.get('/profile', {**passed in json data**}, null, 'script');
})
});
在发生点击事件时调用我的index.js.erb
。但是我想知道如何重命名.js.erb
文件。只有/profile
(或./profile
或profile
)才能专门致电index.js.erb
。如果我重命名文件profile.js.erb
它不起作用(我已尝试将网址设置为profile.js
,profile.js.erb
,profile/profile.js
和其他变体,但这些都无效要求作为萤火虫表演。
基本上我想说出index.js.erb
profile.js.erb
或其他名称,我想知道如何在get
电话中引用它。
谢谢!
编辑:这对我来说非常重要,因为我有2个以上的js.erb文件,我想在不同的事件发生时通过ajax GET调用。所以我不能只坚持一个index.js.erb。我该怎么做呢?什么是onescript.js.erb
和anotherscript.js.erb
的ajax调用?
答案 0 :(得分:0)
索引操作默认情况下为index.html.haml或index.js.erb呈现,但您可以告诉它渲染profile.js.erb,如果这是您想要的...
您的get操作与文件rails服务无关。将您的控制器更改为以下内容:
def index
respond_to do |format|
format.js { render 'profile/profile' }
end
end
答案 1 :(得分:0)
您对/profile/profile.js有正确的路线吗?
resources :profiles
get :profile
end
完成后,您可以再试一次。
答案 2 :(得分:0)
我决定将所有内容放在index.js.erb中,并且只运行我需要的部分...