0
好吧,我有以下的创建操作UJS创建行动正在两个职位
#posts_controller, nested resource under discussions
def create
@post = Post.new(params[:post])
@post.user = current_user
@post.discussion = Discussion.find(params[:discussion_id])
respond_to do |format|
if @post.save!
format.js
format.html { redirect_to discussion_posts_path(@post.discussion), notice: 'Post was successfully created.' }
else
format.html { render :action => "new" }
end
end
end
其脱落以下形式
#index.html.erb#quick_reply
<%= simple_form_for [@discussion, @post], :remote => true do |f| %>
<%= f.input :body, :input_html => {:class => 'span12 short_text_area' } %>
<%= f.submit 'Post Reply', :class => 'btn-primary' %>
<% end %>
开球这个CoffeeScript的
#create.js.coffee
$("#discussion_posts_table").append("<%= escape_javascript(render(@post)) %>");
$("#post_body").val("");
如果我将:remote => true
排除在表格之外,一切都很好,但是将它放入两个模型对象中一个。
任何想法,我可能在这里做错了吗?
'#create.js.coffee'?你确定?不是'#create.js.erb'? –
是的。 Erb仍然评估事件,尽管它不在扩展中。基于这样做这个线程http://stackoverflow.com/questions/11007498/rails-coffeescript-and-erb/11007588 – DVG