*@user = User.new*
*@user.build_profile*

Is that all what you have in the controller in create action?

*@user = User.new(params[:user]) *

is what one would expect.

On Wed, Nov 21, 2012 at 11:17 AM, avinash behera
<[email protected]>wrote:

> I tried with that. But somewhere validations are failing. I had dropped my
> db. Trying to create a user. But in console it says:
> User already exists.
> Not sure.
> In controller I have mentioned as @user.build_profile. Is it fine?
> & in erb file, I am using simple_form_for.
> So can we use fields_for there?
>
>
> On Wed, Nov 21, 2012 at 10:44 AM, Unni <[email protected]> wrote:
>
>> http://stackoverflow.com/a/3283404/1731232
>>
>>
>> http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_accessible
>>
>>
>> On Wed, Nov 21, 2012 at 10:31 AM, Jim Ruther Nill <[email protected]>wrote:
>>
>>>
>>>
>>>
>>> On Wed, Nov 21, 2012 at 12:56 PM, avinash behera <
>>> [email protected]> wrote:
>>>
>>>> I didn't get this :-
>>>> *attr_accessible :address_attributes*
>>>> *
>>>> *
>>>> Why we need to define this in user.rb?
>>>> We already have has_one relation. Will it not be accessing those
>>>> attributes in address model automatically?
>>>>
>>>
>>> fields_for uses <association>_attributes as the name of the fields when
>>> you are using
>>> accepts_nested_attributes_for :association so you need to define this in
>>> attr_accessible
>>>
>>>
>>>>
>>>>
>>>> On Wed, Nov 21, 2012 at 10:11 AM, Unni <[email protected]> wrote:
>>>>
>>>>> add
>>>>>
>>>>> *attr_accessible :address_attributes*
>>>>>
>>>>> in your model.
>>>>>
>>>>> Only the fields that you specify via attr_accessible, are open to mass
>>>>> assignment.
>>>>>
>>>>> Unni
>>>>>
>>>>> On Wed, Nov 21, 2012 at 10:02 AM, Avi <[email protected]>wrote:
>>>>>
>>>>>> Hello All,
>>>>>>
>>>>>> I am stuck in nested attributes:-
>>>>>> here is my code :-
>>>>>>
>>>>>> User.rb :-
>>>>>> has_one :address
>>>>>> accepts_nested_attributes_for :address
>>>>>>
>>>>>> Address.rb :-
>>>>>>
>>>>>> belongs_to :user
>>>>>>
>>>>>> _form.html.erb:-
>>>>>>
>>>>>> <%= simple_form_for @user ,:validate => true do |f| %>
>>>>>>            <%= f.fields_for :address do |d| %>
>>>>>>           <%= d.input :first_name %>
>>>>>>           <%= d.input :last_name %>
>>>>>>           <% end %>
>>>>>>           <%= f.input :email %>
>>>>>>  <% end %>
>>>>>>
>>>>>> in user_controller.rb:-
>>>>>> In new as well as create method I tried with:-
>>>>>> @user = User.new
>>>>>> @user.build_profile
>>>>>>
>>>>>> But still I am getting the error as :-
>>>>>>
>>>>>> Can't mass-assign protected attributes: address_attributes
>>>>>>
>>>>>> Any Suggestions ??
>>>>>>
>>>>>> Thanks....
>>>>>>
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Ruby on Rails: Talk" group.
>>>>>> To post to this group, send email to
>>>>>> [email protected].
>>>>>> To unsubscribe from this group, send email to
>>>>>> [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msg/rubyonrails-talk/-/dd447A7hSYwJ.
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Unni
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Ruby on Rails: Talk" group.
>>>>> To post to this group, send email to [email protected]
>>>>> .
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected].
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ruby on Rails: Talk" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> -------------------------------------------------------------
>>> visit my blog at http://jimlabs.heroku.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ruby on Rails: Talk" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Unni
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Unni

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to