我正在研究从Prototype到jQuery的迁移,并且我们还必须尽可能删除.rjs文件。这里有一个问题:
我在app / views / results文件夹中有update_overall_comment.rjs文件:
page.replace 'overall_comment', :partial => 'results/marker/overall_comment', :locals => {:result => @result}
page.visual_effect(:highlight, 'overall_comment_text_area', :startcolor => '#BDFCC9')
app / views / results / markers文件夹中的_overall_comment.html.erb文件:
<div id="overall_comment">
<div id="overall_comment_edit">
<%= form_for @result,
:remote => true,
:url => { :action => 'update_overall_comment', :id => @result.id } do |f| %>
<%= f.text_area :overall_comment,
:cols => 50,
:rows => 5,
:id => 'overall_comment_text_area',
:onkeydown => "$('overall_comment_submit').enable();" %>
<div>
<%= f.submit t(:save_changes),
:disable_with => I18n.t('working'),
:disabled => true,
:id => "overall_comment_submit"%>
</div>
<% end %>
</div>
</div>
而app / controllers文件夹中的result.controller.rb文件(我只是显示了相关功能):
def update_overall_comment
@result = Result.find(params[:id])
@result.overall_comment = params[:result][:overall_comment]
@result.save
end
我要了解的第一件事是如何将.rjs文件转换为.js.erb。我删除了它,并创建了update_overall_comment.js.erb(在同一文件夹中),其中只包含console.log('...'),但从未见过调用console.log的情况。
你有什么想法 ?
先感谢您。
重命名update_overall_comment.rjs
为update_overall_comment.js.erb
然后在此文件中:
$('#overall_comment').html("<%= j(render 'results/marker/overall_comment') %>");
$('#overall_comment_text_area').effect("highlight", { color: "#BDFCC9" }, 3000);
ps不确定突出显示部分,也用于验证js.erb文件是否已被调用/渲染,我使用alert('something here');
代替console('...');
,但这对于测试ajax调用应该没有太大的区别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句