सहेज नहीं रहा है मैं सरल_फॉर्म का उपयोग करके चेक बॉक्स के माध्यम से एक कर्मचारी आवर्ती कटौती तालिका को लागू करने की कोशिश कर रहा हूं। मेरा कोड काम करता है लेकिन चयनित आवर्ती कटौती मेरी तालिका में सहेजी नहीं जाती है। मैं क्यों काम नहीं कर सकता।रेल 4 सरल_फॉर्म चेक बॉक्स के माध्यम से है_many
यहां मेरे मॉडल हैं।
class Employee < ActiveRecord::Base
belongs_to :club
has_many :employee_recurrents
has_many :recurrents, :through => :employee_recurrents
end
class Recurrent < ActiveRecord::Base
belongs_to :club
has_many :employee_recurrents
has_many :employees, :through => :employee_recurrents
end
class EmployeeRecurrent < ActiveRecord::Base
belongs_to :employee
belongs_to :recurrent
end
प्रवास
class CreateEmployeeRecurrents < ActiveRecord::Migration
def change
create_table :employee_recurrents, :id => false do |t|
t.references :employee
t.references :recurrent
end
add_index :employee_recurrents, [:employee_id, :recurrent_id]
add_index :employee_recurrents, [:recurrent_id, :employee_id]
end
end
रूप
<%= simple_form_for @employee, html: {class: 'form-horizontal' } do |f| %>
<%= f.error_notification %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.association :recurrents,
as: :check_boxes,
label_method: :description,
value_method: :id,
label: 'Recurrent Deductions' %>
<%= f.button :submit, class: 'btn btn-primary' %>
<% end %>
नियंत्रक
def employee_params
params.require(:employee).permit(:first_name, :recurrent_ids)
end
यहाँ
मेरी संपादित लॉग
हैStarted PATCH "/employees/1" for 127.0.0.1 at 2013-08-12 19:38:42 +0800
Processing by EmployeesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"IwWzcT2qQJqHkTumWjb3OD5nJe9xLaA+YezMumer9X8=", "employee"=>{"job_id"=>"5", "manager_id"=>"", "first_name"=>"Mark", "recurrent_ids"=>["1", ""]}, "commit"=>"Update Employee", "id"=>"1"}
[1m[36mActiveRecord::SessionStore::Session Load (1.2ms)[0m [1mSELECT "sessions".* FROM "sessions" WHERE "sessions"."session_id" = '9a8b066a4033f8fa2ed867371ffaa2a3' ORDER BY "sessions"."id" ASC LIMIT 1[0m
[1m[35mUser Load (0.5ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[1m[36mEmployee Load (0.8ms)[0m [1mSELECT "employees".* FROM "employees" WHERE "employees"."id" = $1 ORDER BY last_name, first_name LIMIT 1[0m [["id", "1"]]
Unpermitted parameters: recurrent_ids
[1m[35m (0.6ms)[0m BEGIN
[1m[36mEmployee Exists (1.1ms)[0m [1mSELECT 1 AS one FROM "employees" WHERE ("employees"."email" = '[email protected]' AND "employees"."id" != 1 AND "employees"."club_id" = 1) LIMIT 1[0m
[1m[35m (0.4ms)[0m COMMIT
Redirected to http://localhost:3000/employees
Completed 302 Found in 22ms (ActiveRecord: 4.6ms)
सर्वर लॉग की जरूरत है। मेरे लिए जरूरी नहीं है, लेकिन किसी और के लिए हो सकता है। :) – rmagnum2002
'f.association: recurrents 'अकेले क्या करता है? क्या यह काम करता है (भले ही गलत इनपुट तत्व प्रकार, चेकबॉक्स पर ड्रॉपडाउन कहें)? –
मैं लॉग पोस्ट करूंगा लेकिन मुझे लगता है कि यह "अनिश्चित पैरामीटर: रिकूरेंट_ड्स" कहता है लेकिन मेरे कर्मचारी नियंत्रक में पैराम्स.क्रक्वाययर (: कर्मचारी) .permit (: first_name, recurrent_ids) – markhorrocks