nested-attributes

Getting fields_for and accepts_nested_attributes_for to work with a belongs_to relationship

六月ゝ 毕业季﹏ 提交于 2019-11-26 10:29:21
问题 I cannot seem to get a nested form to generate in a rails view for a belongs_to relationship using the new accepts_nested_attributes_for facility of Rails 2.3. I did check out many of the resources available and it looks like my code should be working, but fields_for explodes on me, and I suspect that it has something to do with how I have the nested models configured. The error I hit is a common one that can have many causes: \'@account[owner]\' is not allowed as an instance variable name

Rails 4 - Strong Parameters - Nested Objects

泄露秘密 提交于 2019-11-26 10:21:42
I've got a pretty simple question. But haven't found a solution so far. So here's the JSON string I send to the server: { "name" : "abc", "groundtruth" : { "type" : "Point", "coordinates" : [ 2.4, 6 ] } } Using the new permit method, I've got: params.require(:measurement).permit(:name, :groundtruth) This throws no errors, but the created database entry contains null instead of the groundtruth value. If I just set: params.require(:measurement).permit! Everything get's saved as expected, but of course, this kills the security provided by strong parameters. I've found solutions, how to permit

Does accepts_nested_attributes_for work with belongs_to?

放肆的年华 提交于 2019-11-26 09:37:08
问题 I have been getting all kinds of conflicting information regarding this basic question, and the answer is pretty crucial to my current problems. So, very simply, in Rails 3, is it allowed or not allowed to use accepts_nested_attributes_for with a belongs_to relationship? class User < ActiveRecord::Base belongs_to :organization accepts_nested_attributes_for :organization end class Organization < ActiveRecord::Base has_many :users end In a view: = form_for @user do |f| f.label :name, \"Name\" f

Rails 4.0 with Devise. Nested attributes Unpermited parameters

筅森魡賤 提交于 2019-11-26 09:29:14
问题 I am working on a web-app using Devise and Rails 4. I have a User model which I have extended with 2 extra form fields such that when a user signs up he can also submit his first/last names. (based on http://blog.12spokes.com/web-design-development/adding-custom-fields-to-your-devise-user-model-in-rails-4/). I now want to add a Institution model. This model has_many :users, and a user belongs_to :institution. I want to be able to register the institution\'s name on the same form I register

accepts_nested_attributes_for with belongs_to polymorphic

狂风中的少年 提交于 2019-11-26 06:57:45
问题 I would like set up a polymorphic relation with accepts_nested_attributes_for . Here is the code: class Contact <ActiveRecord::Base has_many :jobs, :as=>:client end class Job <ActiveRecord::Base belongs_to :client, :polymorphic=>:true accepts_nested_attributes_for :client end When I try to access Job.create(..., :client_attributes=>{...} gives me NameError: uninitialized constant Job::Client 回答1: I've also had a problem with the "ArgumentError: Cannot build association model_name. Are you