On 10 November 2011 16:20, Siva Prasad <newror.u...@gmail.com> wrote:
> On 11/10/2011 6:46 PM, Colin Law wrote:
>>
>> On 10 November 2011 11:46, Siva Prasad<newror.u...@gmail.com>  wrote:
>>>
>>> Gurus,
>>>
>>> Ok, I got chance to rework on it today.As Colin suggested i debugged the
>>> code with  the ruby debugger. Below is the details explained.
>>>
>>> Controllers:
>>>
>>> site_controller.rb
>>> ------------------------------------
>>> def new
>>>
>>> @site=site.new
>>> @site.users.build
>>>
>>> end
>>>
>>> def create
>>>
>>> @site=site.new([:params])
>>> debugger
>>> ###### code i have added #######
>>> @site.users         (using debugger i did p @site.users it prints the
>>> usertable with values i have given in form but role = nil because i dont
>>> take role value in form)
>>> @test=@site.users
>>> @test.role='admin'  (using debugger i did p @site.users it prints the
>>
>> @test is an array of users, I don't understand how you can do
>> @test.role='admin'.  I would have expected it to produce an error.
>>
>>> usertable with values along with role as admin) But DB is not updated.
>>> ##############################
>>>
>>> end
>>
>> You don't appear to have saved anything to the database.
>>
>> Colin
>>
> Colin,
>
> Thanks for your valuable inputs.
>
> if I do @site.users.role (this throws me an error) but not @test.role does
> not

So you are saying that
@site.users.role = 'admin'
throws an error, but
@test = @site.users
@test.role = 'admin'
does not.  I find that difficult to understand.  Can you check that again.
The normal way to do it would be to use
@site.users.each.

If you don't know how to use each then you need to work through some
ruby tutorials.  You can't expect to write rails apps without a good
knowledge of ruby.

>
> Can you let me know  below
>
> 1) how go about adding a role ot user object . coz I have given
> resource.role='sitadmin' in the user controller (which is
> registartion_controller)
> 2) I am doing @site.save ( which I thought would save the data to database)
> If i needed to do explicitly can you pls let me know

The create method you posted above did not have save in it.  Also
after you change the roles you will have to save the user records as
they have changed.

Colin

>
>
> --Siva
>
>
>
> --
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>



-- 
gplus.to/clanlaw

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to