Hi Gurus, I wanted to add siteadmin user(basically a user with a certain role) while creating the site itself. I hope that i have done all the necessary stuff by going through raynb''s railscasts ( http://railscasts.com/episodes/196-nested-model-form-part-1) But could not see user fields being displayed in the site creation form.. Below are the details. I Have two model users and sites. ( user model was created using devise then i customized it). *Below are my models:* *User model* ------------------------------- class User < ActiveRecord::Base *belongs_to :sites ########### I have added this * # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :role, :site_id end ------------------------------ *My site model:* ------------------------------- class Site < ActiveRecord::Base has_many :users, :dependent => :destroy * ########### I have added this* accepts_nested_attributes_for :users * ########### I have added this* end ------------------------------- *Here is the change i have done to the new method of site_controller.rb* ** *-----------------* * *def new @site = Site.new 1.times { @site.users.build } *############ I have added this * respond_to do |format| format.html # new.html.erb format.json { render json: @site } end end *-------------------* ** *Below is the form to which i have made changes, I have added the bold part in the below form ( this form is called by views/sites/new.html.erb) * ** *-------------------------* <%= form_for(@site) do |f| %> <% if @site.errors.any? %> <div id="error_explanation"> <h2>Could not save record due to following errors. Please correct them and continue</h2> <ul> <% @site.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :sitename %><br /> <%= f.text_field :sitename %> </div> <div class="field"> <%= f.label :slogan %><br /> <%= f.text_field :slogan %> </div> * <h3> Site Admin Details </h3> <% f.fields_for :users do |account_fields| %> <%= account_fields.label :text_field, "email" %></br> <%= account_fields.label :text_field, "password" %></br> <%= account_fields.label :text_field, "password_confirmation" %></br> <% end %> ** * <div class="actions"> <%= f.submit %> </div> <% end %> ** *----------------------------* ** After that i have started the rails server could not see any error, But also could not see the user attributes in the site creation page. I could see only the site attributes. Any Inputs are highly appreciated. Thanks In Advance, --S -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 5, 3:19 pm, newrails user <newror.u...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> * <h3> Site Admin Details </h3> > <% f.fields_for :users do |account_fields| %>This should be <%= f.fields_for ... Fred> <%= account_fields.label :text_field, "email" %></br> > <%= account_fields.label :text_field, "password" %></br> > <%= account_fields.label :text_field, "password_confirmation" %></br>> > <% end %> > ** > * <div class="actions"> > <%= f.submit %> > </div> > <% end %> > ** > *----------------------------* > ** > After that i have started the rails server could not see any error, But > also could not see the user attributes in the site creation page. I could > see only the site attributes. > Any Inputs are highly appreciated. > > Thanks In Advance, > --S-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
newrails user
2011-Nov-05 16:03 UTC
Re: Re: Adding a site admin user while creating a site
Thanks Fred, Its working now. :) -S On Sat, Nov 5, 2011 at 9:17 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Nov 5, 3:19 pm, newrails user <newror.u...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > * <h3> Site Admin Details </h3> > > <% f.fields_for :users do |account_fields| %> > > This should be <%= f.fields_for ... > > Fred > > > <%= account_fields.label :text_field, "email" %></br> > > <%= account_fields.label :text_field, "password" %></br> > > <%= account_fields.label :text_field, "password_confirmation" %></br> > > > > > > <% end %> > > ** > > * <div class="actions"> > > <%= f.submit %> > > </div> > > <% end %> > > ** > > *----------------------------* > > ** > > After that i have started the rails server could not see any error, But > > also could not see the user attributes in the site creation page. I could > > see only the site attributes. > > Any Inputs are highly appreciated. > > > > Thanks In Advance, > > --S > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Gurus, > > I wanted to add siteadmin user(basically a user with a certain role) while > creating the site itself. I hope that i have done all the necessary stuff > by going through raynb''s railscasts > (http://railscasts.com/episodes/196-nested-model-form-part-1) But could not > see user fields being displayed in the site creation form.. Below are the > details. > > I Have two model users and sites. ( user model was created using devise > then i customized it). > > Below are my models: > > User model > ------------------------------- > class User < ActiveRecord::Base > belongs_to :sites ########### I have added thisAlso that should be :site singular. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
HI Gurus, I could achieve this, I wanted to updated a filed in user table without taking input from user as asked before.I wanted to set a role to user without taking input from user.So in registration_controller action of (devise) I have set resource.role=''siteadmin''.But its not taking that it always takes the default value provided for the field.Before integrating with nested fileds this piece of code to assign role used ot work.but not anymore. Is there something extra that i am not doing ? Thanks, --S On Sat, Nov 5, 2011 at 9:55 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Gurus, > > > > I wanted to add siteadmin user(basically a user with a certain role) > while > > creating the site itself. I hope that i have done all the necessary > stuff > > by going through raynb''s railscasts > > (http://railscasts.com/episodes/196-nested-model-form-part-1) But > could not > > see user fields being displayed in the site creation form.. Below are the > > details. > > > > I Have two model users and sites. ( user model was created using devise > > then i customized it). > > > > Below are my models: > > > > User model > > ------------------------------- > > class User < ActiveRecord::Base > > belongs_to :sites ########### I have added this > > Also that should be :site singular. > > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
So This is what it is happennig, the role assign works well if i create user normally from its own view, But if I create the user form the site creation view. the role assignment statement (resource.role="siteadmin") doesnt work. This code exisits in the user controller. Any inputs would be appreciated. Thanks, Siva On Tue, Nov 8, 2011 at 5:27 AM, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> HI Gurus, > > I could achieve this, I wanted to updated a filed in user table without > taking input from user as asked before.I wanted to set a role to user > without taking input from user.So in registration_controller action of > (devise) I have set resource.role=''siteadmin''.But its not taking that it > always takes the default value provided for the field.Before integrating > with nested fileds this piece of code to assign role used ot work.but not > anymore. Is there something extra that i am not doing ? > > Thanks, > --S > > On Sat, Nov 5, 2011 at 9:55 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi Gurus, >> > >> > I wanted to add siteadmin user(basically a user with a certain role) >> while >> > creating the site itself. I hope that i have done all the necessary >> stuff >> > by going through raynb''s railscasts >> > (http://railscasts.com/episodes/196-nested-model-form-part-1) But >> could not >> > see user fields being displayed in the site creation form.. Below are >> the >> > details. >> > >> > I Have two model users and sites. ( user model was created using devise >> > then i customized it). >> > >> > Below are my models: >> > >> > User model >> > ------------------------------- >> > class User < ActiveRecord::Base >> > belongs_to :sites ########### I have added this >> >> Also that should be :site singular. >> >> Colin >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 November 2011 00:28, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So This is what it is happennig, the role assign works well if i create user > normally from its own view, But if I create the user form the site creation > view. the role assignment statement (resource.role="siteadmin") doesnt work. > This code exisits in the user controller.I think it most unlikely that the assignment statement (resource.role="siteadmin") does not work. I think that after this statement then resource.role will most definitely be "siteadmin", unless you mean that there is an error of some sort when the statement is run. Presumably what you mean is that later on you find that the role is no longer "siteadmin", presumably due to it not being saved or being overwritten later for example. What you have to do is to follow the logic flow after that statement and work out what is going wrong. I suggest you have a look at the Rails Guide on debugging for some suggestions on how to do this. Look particularly at how to use ruby-debug to break into your code and inspect data and follow the flow. Colin> > Any inputs would be appreciated. > > Thanks, > Siva > > On Tue, Nov 8, 2011 at 5:27 AM, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> HI Gurus, >> >> I could achieve this, I wanted to updated a filed in user table without >> taking input from user as asked before.I wanted to set a role to user >> without taking input from user.So in registration_controller action of >> (devise) I have set resource.role=''siteadmin''.But its not taking that it >> always takes the default value provided for the field.Before integrating >> with nested fileds this piece of code to assign role used ot work.but not >> anymore. Is there something extra that i am not doing ? >> >> Thanks, >> --S >> On Sat, Nov 5, 2011 at 9:55 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> >>> On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> > Hi Gurus, >>> > >>> > I wanted to add siteadmin user(basically a user with a certain role) >>> > while >>> > creating the site itself. I hope that i have done all the necessary >>> > stuff >>> > by going through raynb''s railscasts >>> > (http://railscasts.com/episodes/196-nested-model-form-part-1) But >>> > could not >>> > see user fields being displayed in the site creation form.. Below are >>> > the >>> > details. >>> > >>> > I Have two model users and sites. ( user model was created using >>> > devise >>> > then i customized it). >>> > >>> > Below are my models: >>> > >>> > User model >>> > ------------------------------- >>> > class User < ActiveRecord::Base >>> > belongs_to :sites ########### I have added this >>> >>> Also that should be :site singular. >>> >>> Colin >>> >>> -- >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
jsut to make little more clear this resource.role=''siteadmin'' in the registration_contoller. this registration_controller is devise the controller generated by devise ( I am using devise for authentication.) --Siva On Tue, Nov 8, 2011 at 2:19 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 8 November 2011 00:28, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So This is what it is happennig, the role assign works well if i create > user > > normally from its own view, But if I create the user form the site > creation > > view. the role assignment statement (resource.role="siteadmin") doesnt > work. > > This code exisits in the user controller. > > I think it most unlikely that the assignment statement > (resource.role="siteadmin") does not work. I think that after this > statement then resource.role will most definitely be "siteadmin", > unless you mean that there is an error of some sort when the statement > is run. Presumably what you mean is that later on you find that the > role is no longer "siteadmin", presumably due to it not being saved or > being overwritten later for example. > > What you have to do is to follow the logic flow after that statement > and work out what is going wrong. I suggest you have a look at the > Rails Guide on debugging for some suggestions on how to do this. Look > particularly at how to use ruby-debug to break into your code and > inspect data and follow the flow. > > Colin > > > > > > Any inputs would be appreciated. > > > > Thanks, > > Siva > > > > On Tue, Nov 8, 2011 at 5:27 AM, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> > >> HI Gurus, > >> > >> I could achieve this, I wanted to updated a filed in user table without > >> taking input from user as asked before.I wanted to set a role to user > >> without taking input from user.So in registration_controller action of > >> (devise) I have set resource.role=''siteadmin''.But its not taking that it > >> always takes the default value provided for the field.Before integrating > >> with nested fileds this piece of code to assign role used ot work.but > not > >> anymore. Is there something extra that i am not doing ? > >> > >> Thanks, > >> --S > >> On Sat, Nov 5, 2011 at 9:55 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >>> > >>> On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> > Hi Gurus, > >>> > > >>> > I wanted to add siteadmin user(basically a user with a certain role) > >>> > while > >>> > creating the site itself. I hope that i have done all the necessary > >>> > stuff > >>> > by going through raynb''s railscasts > >>> > (http://railscasts.com/episodes/196-nested-model-form-part-1) But > >>> > could not > >>> > see user fields being displayed in the site creation form.. Below are > >>> > the > >>> > details. > >>> > > >>> > I Have two model users and sites. ( user model was created using > >>> > devise > >>> > then i customized it). > >>> > > >>> > Below are my models: > >>> > > >>> > User model > >>> > ------------------------------- > >>> > class User < ActiveRecord::Base > >>> > belongs_to :sites ########### I have added this > >>> > >>> Also that should be :site singular. > >>> > >>> Colin > >>> > >>> -- > >>> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > >>> To unsubscribe from this group, send email to > >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >>> For more options, visit this group at > >>> http://groups.google.com/group/rubyonrails-talk?hl=en. > >>> > >> > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 November 2011 11:30, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> jsut to make little more clear this resource.role=''siteadmin'' in the > registration_contoller. this registration_controller is devise the > controller generated by devise ( I am using devise for authentication.)I don''t think that changes the fact that if the code is not behaving as you expect and you cannot see the problem by examining the code then you just have to jump in with the debugger and work out what is going wrong. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 usertable with values along with role as admin) But DB is not updated. ############################## end -------------------------------------- *registartion_controller.rb* ----------------------------------------------------- def create resource=build_resource resource=''guestuser'' ( even it wont set user as guest user when i create a user using hte site form.But when i create user from the user view it self the user role is set to guestuser.) end ---------------------------------------------------- *user.rb* ------------------------- belongs_to: site attr_accessible: role ( and few others here) *------------------------- site.rb* --------------------------- has_many: users -------------------------- So I could not set a role for a user from other contoller sites in nested attributes. Can somebody help me on how to set a role for user from the sites table ( in the nested attribute model) ----Siva On 11/8/2011 5:00 PM, newrails user wrote:> > jsut to make little more clear this resource.role=''siteadmin'' in the > registration_contoller. this registration_controller is devise the > controller generated by devise ( I am using devise for authentication.) > > --Siva > On Tue, Nov 8, 2011 at 2:19 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org > <mailto:clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> wrote: > > On 8 November 2011 00:28, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > So This is what it is happennig, the role assign works well if i > create user > > normally from its own view, But if I create the user form the > site creation > > view. the role assignment statement (resource.role="siteadmin") > doesnt work. > > This code exisits in the user controller. > > I think it most unlikely that the assignment statement > (resource.role="siteadmin") does not work. I think that after this > statement then resource.role will most definitely be "siteadmin", > unless you mean that there is an error of some sort when the statement > is run. Presumably what you mean is that later on you find that the > role is no longer "siteadmin", presumably due to it not being saved or > being overwritten later for example. > > What you have to do is to follow the logic flow after that statement > and work out what is going wrong. I suggest you have a look at the > Rails Guide on debugging for some suggestions on how to do this. Look > particularly at how to use ruby-debug to break into your code and > inspect data and follow the flow. > > Colin > > > > > > Any inputs would be appreciated. > > > > Thanks, > > Siva > > > > On Tue, Nov 8, 2011 at 5:27 AM, newrails user > <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > >> > >> HI Gurus, > >> > >> I could achieve this, I wanted to updated a filed in user > table without > >> taking input from user as asked before.I wanted to set a role > to user > >> without taking input from user.So in registration_controller > action of > >> (devise) I have set resource.role=''siteadmin''.But its not > taking that it > >> always takes the default value provided for the field.Before > integrating > >> with nested fileds this piece of code to assign role used ot > work.but not > >> anymore. Is there something extra that i am not doing ? > >> > >> Thanks, > >> --S > >> On Sat, Nov 5, 2011 at 9:55 PM, Colin Law > <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org <mailto:clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> wrote: > >>> > >>> On 5 November 2011 15:19, newrails user <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > >>> > Hi Gurus, > >>> > > >>> > I wanted to add siteadmin user(basically a user with a > certain role) > >>> > while > >>> > creating the site itself. I hope that i have done all the > necessary > >>> > stuff > >>> > by going through raynb''s railscasts > >>> > > (http://railscasts.com/episodes/196-nested-model-form-part-1) But > >>> > could not > >>> > see user fields being displayed in the site creation form.. > Below are > >>> > the > >>> > details. > >>> > > >>> > I Have two model users and sites. ( user model was created > using > >>> > devise > >>> > then i customized it). > >>> > > >>> > Below are my models: > >>> > > >>> > User model > >>> > ------------------------------- > >>> > class User < ActiveRecord::Base > >>> > belongs_to :sites ########### I have added > this > >>> > >>> Also that should be :site singular. > >>> > >>> Colin > >>> > >>> -- > >>> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > >>> To unsubscribe from this group, send email to > >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > >>> For more options, visit this group at > >>> http://groups.google.com/group/rubyonrails-talk?hl=en. > >>> > >> > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > gplus.to/clanlaw <http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 November 2011 11:46, Siva Prasad <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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=-65l7jV7mgC35hZtpMjTiwg@public.gmane.org > @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. > ############################## > > endYou don''t appear to have saved anything to the database. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11/10/2011 6:46 PM, Colin Law wrote:> On 10 November 2011 11:46, Siva Prasad<newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 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 --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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 November 2011 16:20, Siva Prasad <newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 11/10/2011 6:46 PM, Colin Law wrote: >> >> On 10 November 2011 11:46, Siva Prasad<newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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=-65l7jV7mgC35hZtpMjTiwg@public.gmane.org >>> @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 > notSo 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 knowThe 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sorry Now i got it. you meant to say read each user object from the @site.users and operate on them. thanks a lot :-) On 11/10/2011 10:05 PM, Colin Law wrote:> On 10 November 2011 16:20, Siva Prasad<newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 11/10/2011 6:46 PM, Colin Law wrote: >>> On 10 November 2011 11:46, Siva Prasad<newror.user-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.