Hello - Being new to Ruby and Rails I am finding some hurdles that kind of slow my progress. 1. What is the difference between the 2 statements: staff = Staff.find(params[:id]) and @staff = Staff.find(params[:id]) I find books and articles using either of them but I fail to grasp why this should be different 2. This piece of code does not work and I have no idea why: controlller: @subscriber = Subscriber.new(params[:subscriber]) @subscriber.activate @subscriber.save the function activate is defined in the model: def activate @active = 1 end (active beeing one of the row of the table). Result: this does not set active to 1. If in my controller I set @subscriber.active = 1 then it works and the row is saved with active set to 1. Thanks for your help !!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, talking about rails, if you do in your controller staff = Staff.find(1), then you can''t use that in your views, because it goes out of scope, instead, if you use @staff, it will be available in your view. I suggest you to read something about scope and variables. For the second problem, try tu use active = 1 instead of @active = 1. I''m not sure let me know f it works -- Posted via http://www.ruby-forum.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the answer. I know understand about the scope thing. I''ve tried using "active = 1" in my model but this still does not work. Any further idea? On Nov 11, 10:16 am, Oscar Del ben <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Well, talking about rails, if you do in your controller > staff = Staff.find(1), then you can''t use that in your views, because it > goes out of scope, instead, if you use @staff, it will be available in > your view. I suggest you to read something about scope and variables. > > For the second problem, try tu use active = 1 instead of @active = 1. > I''m not sure let me know f it works > -- > Posted viahttp://www.ruby-forum.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-11 10:59 UTC
Re: 2 "newbie questions"
On the model: try this: def activate self.active = 1 self.save #you might even remove this, not sure end or, if it does not work, you can always use def activate(user_id) user = User.find_by_id(user_id) user.active = 1 end and then in the controller User.activate(222) #or whatever the id is Best regards, Felipe On Nov 11, 2:50 am, Vincent <vincent.birlo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the answer. I know understand about the scope thing. > I''ve tried using "active = 1" in my model but this still does not > work. Any further idea? > > On Nov 11, 10:16 am, Oscar Del ben <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Well, talking about rails, if you do in your controller > > staff = Staff.find(1), then you can''t use that in your views, because it > > goes out of scope, instead, if you use @staff, it will be available in > > your view. I suggest you to read something about scope and variables. > > > For the second problem, try tu use active = 1 instead of @active = 1. > > I''m not sure let me know f it works > > -- > > Posted viahttp://www.ruby-forum.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
def activate self.active = 1 end -> This works! Many thanks Felipe! On Nov 11, 10:59 am, "felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On the model: > > try this: > > def activate > self.active = 1 > self.save #you might even remove this, not sure > end > > or, if it does not work, you can always use > > def activate(user_id) > user = User.find_by_id(user_id) > user.active = 1 > end > > and then in the controller > > User.activate(222) #or whatever the id is > > Best regards, > > Felipe > > On Nov 11, 2:50 am, Vincent <vincent.birlo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for the answer. I know understand about the scope thing. > > I''ve tried using "active = 1" in my model but this still does not > > work. Any further idea? > > > On Nov 11, 10:16 am, Oscar Del ben <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > Well, talking about rails, if you do in your controller > > > staff = Staff.find(1), then you can''t use that in your views, because it > > > goes out of scope, instead, if you use @staff, it will be available in > > > your view. I suggest you to read something about scope and variables. > > > > For the second problem, try tu use active = 1 instead of @active = 1. > > > I''m not sure let me know f it works > > > -- > > > Posted viahttp://www.ruby-forum.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---