mercredi 8 novembre 2017

Creartor must exist error Ruby on Rails

I have two models, issues and user

User:

class User < ApplicationRecord
    has_many :created_issues, :class_name => 'Issue', :foreign_key => 'creator_id'
    has_many :assigned_issues, :class_name => 'Issue', :foreign_key => 'assigned_id'
end

Issue:

class Issue < ApplicationRecord
    belongs_to     :creator,
                   :class_name => "User",
                   :foreign_key  => "creator_id"

    belongs_to     :assigned,
                   :class_name => "User",
                   :foreign_key  => "assigned_id" 
end

Migration file:

class CreateIssues < ActiveRecord::Migration[5.1]
  def change
    create_table :issues do |t|
      t.string :title
      t.text :description
      t.integer :assigned_id
      t.string :tipo
      t.string :prioridad
      t.string :estado
      t.references :creator
      t.references :assigned

     add_foreign_key :issues, :users, column: :creator_id, primary_key: :id
     add_foreign_key :issues, :users, column: :assigned_id, primary_key: :id
      t.timestamps
    end
  end
end

Part of the schema:

ActiveRecord::Schema.define(version: 20171030104901) do

create_table "issues", force: :cascade do |t|
    t.string "title"
    t.text "description"
    t.integer "assigned_id"
    t.string "tipo"
    t.string "prioridad"
    t.string "estado"
    t.integer "creator_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false`enter code here`
    t.index ["assigned_id"], name: "index_issues_on_assigned_id"
    t.index ["creator_id"], name: "index_issues_on_creator_id"
  end

end

in the form I'm getting that he field Creator must exists, but i see it fine in the insert:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"2yY/0x6961iIb9PxcyQAKHUSRqEj+zwQ91uPwHibU9tWjEXqiKMqp3vwzI70FVI2agtYhPgljFPDZjVZV4cmyg==", "issue"=>{"title"=>"asdsad", "description"=>"asdsa", "creator_id"=>"2", "tipo"=>"adas", "prioridad"=>"dsdaasd", "assigned_id"=>"3"}, "commit"=>"Create Issue"}
Unpermitted parameter: :creator_id
(0.1ms) begin transaction
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
(0.1ms) rollback transaction

any help ?

Aucun commentaire:

Enregistrer un commentaire