hello every body ! i have a little problem i have created a scaffold Zone witch contain : name , interface and description as attribute all works fine but when i add this line to my model : class Zone < ActiveRecord::Base validates_presence_of :name, :message => "Missing name " end i have an error when the name is empty ! this is the error : You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.inject any help please i have searched a lot but i don''t found any solution :( have i forgot any step ? thanks a lot -- Cordialement Abdelkarim Fitouri Membre Securinets :http://www.securinets.com <http://www.securinets.com> Élève ingénieur . Technicien Réseaux et Systèmes : Agence Universitaire de la Francophonie (AUF) Cnf Tunis . -- 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 Wed, Jan 19, 2011 at 5:58 PM, abdelkrim fitouri <abdou.abf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> hello every body ! > > i have a little problem > > i have created a scaffold Zone witch contain : name , interface and > description as attribute > > all works fine but when i add this line to my model : > > class Zone < ActiveRecord::Base > > validates_presence_of :name, :message => "Missing name " > > end > > i have an error when the name is empty ! > > > > this is the error : > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.inject > > Hi! Can you post more data on the error --- it probably tells you a linenumber and class where this is occurring. I suspect that the issue might be in your view code?? At least I have had such... anyhow more info should help.> > > any help please i have searched a lot but i don''t found any solution :( have i forgot any step ? > > thanks a lot > > > > > -- > Cordialement > Abdelkarim Fitouri > Membre Securinets :http://www.securinets.com <http://www.securinets.com> > Élève ingénieur . > Technicien Réseaux et Systèmes : Agence Universitaire de la Francophonie > (AUF) > Cnf Tunis . > > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 January 2011 23:58, abdelkrim fitouri <abdou.abf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello every body ! > > i have a little problem > > i have created a scaffold Zone witch contain : name , interface and > description as attribute > > all works fine but when i add this line to my model : > > class Zone < ActiveRecord::Base > > validates_presence_of :name, :message => "Missing name " > > end > > i have an error when the name is empty ! > > > > this is the error : > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.injectLook carefully at the error and if necessary the stack trace and you should find an indication of where it is failing in your code. Look at that line and you will likely find a call of inject, the error is telling you that the object you are calling inject on is nil. Colin> > > any help please i have searched a lot but i don''t found any solution :( > have i forgot any step ? > > > thanks a lot > > > > > -- > Cordialement > Abdelkarim Fitouri > Membre Securinets :http://www.securinets.com > Élève ingénieur . > Technicien Réseaux et Systèmes : Agence Universitaire de la Francophonie > (AUF) > Cnf Tunis . > > > -- > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hello thank you for your reply i will explain to you a little more the problem : i created a scafold : ./script/generate scaffold Zone name:string interface:string description:string all works fine . than i changed <%= f.text_field :interface %> to <%= f.select :interface , @table_Interfaces %> @table_interfaces is an array witch contains all network interface in the linux machine . in my controller i have : @interfaces=%x[ifconfig|grep Link|cut -d " " -f 1] @table_Interfaces=-fDpYTK8McCwOlF/BwnhKgw@public.gmane.org(" ") and at this step all works fine . i can make all the operation on my object Zone. then i wanted to make some validation in the model . i aded this in my model file Zone.rb : class Zone < ActiveRecord::Base validates_presence_of :name end Now when i want to create a new zone : if i enter all the attribute it works fine . if i don''t enter the name i have this error : Showing app/views/zones/new.html.erb where line #12 raised: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.inject Extracted source (around line #12): <%= f.select :interface , @table_Interfaces %> witch mean that the model don''t know the object @table_Interfaces witch is declared only on the controller no ? should I add something in my model file related to @table_Interfaces ? thank you very much for your help . i am a newbie in ROR world but i have searched a lot without result . On 20 jan, 09:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 19 January 2011 23:58, abdelkrim fitouri <abdou....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > hello every body ! > > > i have a little problem > > > i have created a scaffold Zone witch contain : name , interface and > > description as attribute > > > all works fine but when i add this line to my model : > > > class Zone < ActiveRecord::Base > > > validates_presence_of :name, :message => "Missing name " > > > end > > > i have an error when the name is empty ! > > > this is the error : > > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.inject > > Look carefully at the error and if necessary the stack trace and you > should find an indication of where it is failing in your code. Look > at that line and you will likely find a call of inject, the error is > telling you that the object you are calling inject on is nil. > > Colin > > > > > any help please i have searched a lot but i don''t found any solution :( > > have i forgot any step ? > > > thanks a lot > > > -- > > Cordialement > > Abdelkarim Fitouri > > Membre Securinets :http://www.securinets.com > > Élève ingénieur . > > Technicien Réseaux et Systèmes : Agence Universitaire de la Francophonie > > (AUF) > > Cnf Tunis . > > > -- > > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 January 2011 21:22, abdelkarim <abdou.abf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello thank you for your replyPlease don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate points in previous message. Thanks> > i will explain to you a little more the problem : > > i created a scafold : > > ./script/generate scaffold Zone name:string interface:string > description:string > > all works fine . > > than i changed <%= f.text_field :interface %> to > <%= f.select :interface , @table_Interfaces %> > > @table_interfaces is an array witch contains all network interface in > the linux machine . > > in my controller i have : > > @interfaces=%x[ifconfig|grep Link|cut -d " " -f 1] > @table_Interfaces=-fDpYTK8McCwOlF/BwnhKgw@public.gmane.org(" ")I suggest you use ruby-debug to break in here and inspect the variables to see what is going on. Have a look at the Rails Guide on debugging to find out how. Also have you tried running the code above in the ruby console to see what it generates? A secondary issue, but the rails convention for naming is @table_interfaces (all lower case). If you stick to the rails conventions your life will generally be simpler. Colin> > and at this step all works fine . i can make all the operation on my > object Zone. > > > then i wanted to make some validation in the model . > > i aded this in my model file Zone.rb : > > class Zone < ActiveRecord::Base > validates_presence_of :name > end > > Now when i want to create a new zone : > > if i enter all the attribute it works fine . > > if i don''t enter the name i have this error : > > Showing app/views/zones/new.html.erb where line #12 raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.inject > > Extracted source (around line #12): > <%= f.select :interface , @table_Interfaces %> > > > witch mean that the model don''t know the object @table_Interfaces > witch is declared only on the controller no ? > > should I add something in my model file related to @table_Interfaces ? > > thank you very much for your help . i am a newbie in ROR world but i > have searched a lot without result . > > > On 20 jan, 09:29, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 19 January 2011 23:58, abdelkrim fitouri <abdou....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> > hello every body ! >> >> > i have a little problem >> >> > i have created a scaffold Zone witch contain : name , interface and >> > description as attribute >> >> > all works fine but when i add this line to my model : >> >> > class Zone < ActiveRecord::Base >> >> > validates_presence_of :name, :message => "Missing name " >> >> > end >> >> > i have an error when the name is empty ! >> >> > this is the error : >> >> > You have a nil object when you didn''t expect it! >> > You might have expected an instance of Array. >> > The error occurred while evaluating nil.inject >> >> Look carefully at the error and if necessary the stack trace and you >> should find an indication of where it is failing in your code. Look >> at that line and you will likely find a call of inject, the error is >> telling you that the object you are calling inject on is nil. >> >> Colin >> >> >> >> > any help please i have searched a lot but i don''t found any solution :( >> > have i forgot any step ? >> >> > thanks a lot >> >> > -- >> > Cordialement >> > Abdelkarim Fitouri >> > Membre Securinets :http://www.securinets.com >> > Élève ingénieur . >> > Technicien Réseaux et Systèmes : Agence Universitaire de la Francophonie >> > (AUF) >> > Cnf Tunis . >> >> > -- >> > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.