Adding attributes to models

I have added these two new attributes to the hypervisor model (hyperpass, hyperuser) and created the db migration file.

However when I run foreman I get the following error:

/opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:81:in method_missing&#39;: undefined local variable or methodhyperuser' for #<Class:0x7f3abbc13868> (NameError)
from /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing'

I am not sure what I am missing but it looks like it has something to do with the search functionality. Any ideas?

Hypervisor.rb

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri, :kind, hyperuser, hyperpass
attr_reader :host validates_presence_of :name, :uri, :kind
validates_uniqueness_of :name, :uri
before_save :try_to_connect
default_scope :order => 'LOWER(hypervisors.name)'

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

> I have added these two new attributes to the hypervisor model (hyperpass,
> hyperuser) and created the db migration file.
did you ran the migration too?

> However when I run foreman I get the following error:
> /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:81:in
> method_missing&#39;: undefined local variable or methodhyperuser' for
> #<Class:0x7f3abbc13868> (NameError)
> from
> /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in
> `method_missing'
>
> I am not sure what I am missing but it looks like it has something to do
> with the search functionality. Any ideas?
Search is just a fallback, due the dynamic methods it creates, so it
didnt find the real method, and tried to figure out if its a search
method (via method missing) instead.

··· On Mon, Oct 24, 2011 at 3:59 AM, Corey Osman wrote:

Hypervisor.rb
class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri, :kind,
hyperuser, hyperpass
attr_reader :host validates_presence_of :name, :uri, :kind
validates_uniqueness_of :name, :uri
before_save :try_to_connect
default_scope :order => ‘LOWER(hypervisors.name)’

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

>> I have added these two new attributes to the hypervisor model (hyperpass,
>> hyperuser) and created the db migration file.
> did you ran the migration too?

yes. The schema was updated.
>
>> However when I run foreman I get the following error:
>> /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:81:in
>> method_missing&#39;: undefined local variable or methodhyperuser' for
>> #<Class:0x7f3abbc13868> (NameError)
>> from
>> /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in
>> `method_missing'
>>
>> I am not sure what I am missing but it looks like it has something to do
>> with the search functionality. Any ideas?
> Search is just a fallback, due the dynamic methods it creates, so it
> didnt find the real method, and tried to figure out if its a search
> method (via method missing) instead.

I noticed that if I removed hyperuser and hyperpass from the attr_accessible line I received no errors.

··· On Oct 23, 2011, at 9:29 PM, Ohad Levy wrote: > On Mon, Oct 24, 2011 at 3:59 AM, Corey Osman wrote:

Hypervisor.rb
class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri, :kind,
hyperuser, hyperpass
attr_reader :host validates_presence_of :name, :uri, :kind
validates_uniqueness_of :name, :uri
before_save :try_to_connect
default_scope :order => ‘LOWER(hypervisors.name)’

Corey Osman
corey@logicminds.biz

Green I.T and Datacenter Automation Specialist

fwiw:

I think the 'hyperuser' and 'hyperpass' should be declared with a
colon in front of it like:

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri,
:kind, :hyperuser, :hyperpass

as opposed to

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri,
:kind, hyperuser, hyperpass

Tim

··· Op 24 oktober 2011 07:37 heeft Corey Osman het volgende geschreven: > > > > > On Oct 23, 2011, at 9:29 PM, Ohad Levy wrote: > > On Mon, Oct 24, 2011 at 3:59 AM, Corey Osman wrote: > > I have added these two new attributes to the hypervisor model (hyperpass, > > hyperuser) and created the db migration file. > > did you ran the migration too? > > yes. The schema was updated. > > However when I run foreman I get the following error: > > /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:81:in > > `method_missing': undefined local variable or method `hyperuser' for > > # (NameError) > > from > > /opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in > > `method_missing' > > I am not sure what I am missing but it looks like it has something to do > > with the search functionality. Any ideas? > > Search is just a fallback, due the dynamic methods it creates, so it > didnt find the real method, and tried to figure out if its a search > method (via method missing) instead. > > I noticed that if I removed hyperuser and hyperpass from the attr_accessible > line I received no errors. > > > Hypervisor.rb > > class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri, :kind, > > hyperuser, hyperpass > > attr_reader :host validates_presence_of :name, :uri, :kind > > validates_uniqueness_of :name, :uri > > before_save :try_to_connect > > default_scope :order => 'LOWER(hypervisors.name)' > > Corey Osman > > corey@logicminds.biz > > Green I.T and Datacenter Automation Specialist > > > > >

I dropped to the script/console and created a new hypervisor and noticed the new attributes were not in the table.

I forgot to specify the environment when I did the migration so hyperuser and hyperpass didn't exist.

It works now :slight_smile:

http://pastebin.com/6NnwP1dZ

What does attr_accessible do exactly since the variables in the table are automatically inherited in the model.

Corey Osman
corey@logicminds.biz
678-348-0582 Pacific Time

Green I.T and Datacenter Automation Specialist

··· On Oct 26, 2011, at 1:45 AM, Tim Speetjens wrote:

fwiw:

I think the ‘hyperuser’ and ‘hyperpass’ should be declared with a
colon in front of it like:

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri,
:kind, :hyperuser, :hyperpass

as opposed to

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri,
:kind, hyperuser, hyperpass

Tim

Op 24 oktober 2011 07:37 heeft Corey Osman corey@logicminds.biz het
volgende geschreven:

On Oct 23, 2011, at 9:29 PM, Ohad Levy wrote:

On Mon, Oct 24, 2011 at 3:59 AM, Corey Osman corey@logicminds.biz wrote:

I have added these two new attributes to the hypervisor model (hyperpass,

hyperuser) and created the db migration file.

did you ran the migration too?

yes. The schema was updated.

However when I run foreman I get the following error:

/opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:81:in

method_missing': undefined local variable or methodhyperuser’ for

#Class:0x7f3abbc13868 (NameError)

from

/opt/foreman3/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in

`method_missing’

I am not sure what I am missing but it looks like it has something to do

with the search functionality. Any ideas?

Search is just a fallback, due the dynamic methods it creates, so it
didnt find the real method, and tried to figure out if its a search
method (via method missing) instead.

I noticed that if I removed hyperuser and hyperpass from the attr_accessible
line I received no errors.

Hypervisor.rb

class Hypervisor < ActiveRecord::Base attr_accessible :name, :uri, :kind,

hyperuser, hyperpass

attr_reader :host validates_presence_of :name, :uri, :kind

validates_uniqueness_of :name, :uri

before_save :try_to_connect

default_scope :order => ‘LOWER(hypervisors.name)’

Corey Osman

corey@logicminds.biz

Green I.T and Datacenter Automation Specialist