远程真实的形式错误

时间:2013-05-23 11:31:09

标签: javascript ruby-on-rails-3.2 formtastic

当我使用时:remote =>成功提交后,真正的formtastic不会自动删除表格

如果我使用远程表单来更新数据,如下面的代码所示,表单始终与该模型相关联,不允许我保存新模型,即使我尝试使用创建新模型构建并尝试通过js中的本地传递ti

所以继承了形式的观点

<%= semantic_form_for @deliverable,:remote=>true do |f| %>
<%= f.input :quantity, :as => :number , :name => "items"%>
<%= f.input :product_id, :as => :select, :collection => current_user.products.all %>
<%= f.actions%>
<% end %>

这是控制器

def create
@micropost = current_user.microposts.find(Rails.cache.read('mp_id'))
@deliverable = @micropost.deliverables.build(params[:deliverable])
@curr_product = current_user.products.find(params[:deliverable][:product_id])
@deliverable.del_price_cents = @deliverable.quantity * @curr_product.price_cents
if @deliverable.save
   @del_items = @micropost.deliverables.find(:all)

  respond_to do |format|
    format.html {redirect_to root_path}
    format.js
 end   
else
  respond_to do |format|
    format.html {redirect_to root_path}
    format.js    {render :text => @deliverable.errors.full_messages.to_s}
 end   




end
end
def edit
 @deliverable = Deliverable.find(params[:id])
 respond_to do |format|

   format.js 
 end

 end
 def update
 @deliholder = Deliverable.find(params[:id])
 if @deliholder.update_attributes(params[:deliverable])
 @micropost = current_user.microposts.find(Rails.cache.read('mp_id'))

 @del_items = @micropost.deliverables.find(:all) 
 @deliverable = @micropost.deliverables.new


  respond_to do |format|
    format.js 
  end
  else
  respond_to do |format|
    format.html {redirect_to root_path}
    format.js    {render :text => @deliverable.errors.full_messages.to_s}
  end 
 end  
end

并且继承了编辑的js视图

$("#deliver-list").hide();
$("#deliver-holder").html("<%= escape_javascript( render(    'shared/deliverable_formtastic',:locals => {:deliverable => @deliverable }))%>");

和js for update

alert("the deliverable has been updated ")
$("#deliver-list").html("<%= escape_javascript( render(  'shared/deliverable_list' ,:locals => {:del_items => @del_items } ))%>");
$("#deliver-list").show();
$("#deliver-holder").empty();
$("#deliver-holder").html("<%= escape_javascript( render( 'shared/deliverable_formtastic',:locals => {:deliverable => @deliverable }))%>");

我尝试用@deliholder替换@deliverable进行更新,如上所示,没有区别,传递或不传递js locals中的@deliverables也没什么区别

create.js

alert("the deliverable has been saved to the  bill ");
$('#fc')[0].reset();
$("#deliver-list").html("<%= escape_javascript( render(  'shared/deliverable_list' ,:locals => {:del_items => @del_items } ))%>");

0 个答案:

没有答案