Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在另一个模型中渲染表单时不保存Rails 4对象_Ruby On Rails_Forms_Renderpartial - Fatal编程技术网

Ruby on rails 在另一个模型中渲染表单时不保存Rails 4对象

Ruby on rails 在另一个模型中渲染表单时不保存Rails 4对象,ruby-on-rails,forms,renderpartial,Ruby On Rails,Forms,Renderpartial,我在Contact下嵌套了一个调用模型,一个Contact有许多调用。在Edit#Contact视图中,我呈现表单以创建新呼叫。当我提交表单时,参数会被提交,但新的调用对象不会被保存 请注意,如果我只是从new#Call视图(表单未在Edit#Contact视图中呈现)创建一个新调用,则调用对象将被保存,因此在Edit Contact视图中呈现表单时这只是一个问题 控制台输出: Started PATCH "/contacts/54" for 127.0.0.1 at 2014-12-30 15

我在Contact下嵌套了一个调用模型,一个Contact有许多调用。在Edit#Contact视图中,我呈现表单以创建新呼叫。当我提交表单时,参数会被提交,但新的调用对象不会被保存

请注意,如果我只是从new#Call视图(表单未在Edit#Contact视图中呈现)创建一个新调用,则调用对象将被保存,因此在Edit Contact视图中呈现表单时这只是一个问题

控制台输出:

Started PATCH "/contacts/54" for 127.0.0.1 at 2014-12-30 15:29:05 -0500
Processing by ContactsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"wyo0S3G5NHdfFr3e2DFw/ArhA7ouKdljCP5XaHMQ5Gc=", "contact"=>{"name"=>"Sample User 3", "entity"=>"Company 3", "phone"=>"888-888-8888", "alt_phone"=>"", "dead_phone"=>"", "email"=>"sample3@example.com", "alt_email"=>"", "dead_email"=>"", "body"=>""}, "call"=>{"dial_id"=>"1", "conversation_id"=>"1", "investing_id"=>"1", "timing_id"=>"1", "motivator_id"=>"1"}, "commit"=>"Save", "id"=>"54"}
  User Load (0.2ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
  Contact Load (0.1ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."id" = ?  ORDER BY updated_at DESC LIMIT 1  [["id", 54]]
   (0.1ms)  begin transaction
   (0.1ms)  commit transaction
  Contact Store (725.1ms)  {"id":54,"exception":["Elasticsearch::Transport::Transport::Errors::NotFound","[404] {\"error\":\"IndexMissingException[[contacts_development] missing]\",\"status\":404}"]}
[404] {"error":"IndexMissingException[[contacts_development] missing]","status":404}
  Contact Load (0.5ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."user_id" = ? AND (id < 54)  ORDER BY updated_at DESC LIMIT 1  [["user_id", 1]]
  Property Load (0.2ms)  SELECT "properties".* FROM "properties"  WHERE "properties"."contact_id" = ?  [["contact_id", 54]]
  CACHE (0.0ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."id" = ?  ORDER BY updated_at DESC LIMIT 1  [["id", "54"]]
  CACHE (0.0ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."id" = ?  ORDER BY updated_at DESC LIMIT 1  [["id", "54"]]
  Dial Load (0.2ms)  SELECT "dials".* FROM "dials"
  Conversation Load (0.2ms)  SELECT "conversations".* FROM "conversations"
  Investing Load (0.2ms)  SELECT "investings".* FROM "investings"
  Timing Load (0.1ms)  SELECT "timings".* FROM "timings"
  Motivator Load (0.1ms)  SELECT "motivators".* FROM "motivators"
  Rendered calls/_form.html.haml (11.9ms)
  Contact Load (0.5ms)  SELECT  "contacts".* FROM "contacts"   ORDER BY updated_at DESC LIMIT 1
  Contact Load (0.4ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."user_id" = ?  ORDER BY updated_at ASC LIMIT 1  [["user_id", 1]]
  Rendered contacts/edit.html.haml within layouts/application (29.7ms)
  Contact Load (0.5ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."user_id" = ?  ORDER BY updated_at DESC LIMIT 1  [["user_id", 1]]
  CACHE (0.0ms)  SELECT  "contacts".* FROM "contacts"  WHERE "contacts"."user_id" = ?  ORDER BY updated_at DESC LIMIT 1  [["user_id", 1]]
Completed 200 OK in 1039ms (Views: 304.1ms | Searchkick: 725.1ms | ActiveRecord: 3.6ms)
在contact#edit视图中呈现新呼叫表单,如下所示:

= render 'calls/form'
作为一个附带的问题,我无法找出这个路径的形式。因此,为了一次解决一个问题,我只需要用非常冗长的路径作为占位符

以下是Contacts Controller中的编辑方法:

  def edit
    @contact = Contact.find(params[:id])
    @user = @contact.user
    @new_call = @contact.calls.build
    authorize @contact
  end
def create
    @contact = Contact.find(params[:contact_id])
    @call = Call.new(call_params)
    @call.contact_id = @contact.id
    @call.user_id = current_user.id

    if @call.save
      flash[:notice] = "Your Call was successfully posted."
      redirect_to edit_contact_path(@contact)
    else
      flash[:error] = "Your Call was not posted. Please try again."
      redirect_to edit_contact_path(@contact)
    end
  end
在呼叫控制器中创建
方法:

  def edit
    @contact = Contact.find(params[:id])
    @user = @contact.user
    @new_call = @contact.calls.build
    authorize @contact
  end
def create
    @contact = Contact.find(params[:contact_id])
    @call = Call.new(call_params)
    @call.contact_id = @contact.id
    @call.user_id = current_user.id

    if @call.save
      flash[:notice] = "Your Call was successfully posted."
      redirect_to edit_contact_path(@contact)
    else
      flash[:error] = "Your Call was not posted. Please try again."
      redirect_to edit_contact_path(@contact)
    end
  end
routes.rb:

  resources :contacts do
    resources :properties
    resources :calls

    collection do
      post :import
      get :database
    end
  end

表单提交的参数有联系人参数和呼叫参数。因此,数据正在进入服务器。您的contact#edit controller方法是什么样子的?我猜path的表单#指向错误的操作。您可以使用:action=>“your action”以表单_形式指定操作,以确保其指向正确的操作@我添加了编辑联系人控制器方法。@trueinViso我将此添加到[contact.find(params[:id])、contact.find(params[:id]).calls.new]、:url=>{action:“create”}do | f |的部分
=form_表单中,但仍然得到相同的结果。正在提交参数,但未创建调用对象。我将在操作中指定控制器,是调用吗?Try:url=>url\u for(:controller=>'mycontroller',:action=>'myaction')这是来自