Merge Attribute after Rails find query

Hi Everyone,

   I have small doubt in rails. I hope i will get solution from here.

I am using rails find query like this

  def self.data_query(params,label)
       :select => "b.BaseManagedEntityInternalId,
c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}, s.HealthState,
       :joins => "as b INNER JOIN #{TABLE_NAMES[label]} as c ON
c.basemanagedentityid = b.basemanagedentityid
                   INNER JOIN state as s ON b.basemanagedentityid =
       :conditions => BaseManagedEntity.all_conditions(params,
       :order => "s.LastModified DESC",
       :group => "b.BaseManagedEntityInternalId, s.HealthState,
s.LastModified, c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}" )

  DEVICE_NAMES = {"windows" => "NetworkName", "unix" =>
                  "network" =>

  DEVICE_IPS = {"windows" => "IPAddress", "unix" =>
                  "network" =>

  TABLE_NAMES = {"windows" => "mt_computer", "unix" =>
                   "network" => "mt_networkdevice"}

  HEALTH_STATES = {"Normal" => 1, "Warning" => 2, "Critical" => 3,
"Healthy" => 1 }

The abvoe method will call from this method

  def self.all_devices(params)
    all_devices = data_query(params, "windows") + data_query(params,
"unix") + data_query(params, "network")
    all_devices.paginate((params[:page] || 1), CONSTANTS['PAGINATE']
['TEN'] )

I want to merge a attribute called "device_type"( which i will define
as attr_accessor)
after find query based on the label i used so that i can use attribute
in the views.

How can i do that. Please help me in this issue.

In ruby if you have a hash, for e.g. :
hash = {}
then you can say this: hash.merge!(“name” => “something”)
this will append that label inside the hash.


  Can we do that after find query that i mentioned above. I want to
apply for all records that i got from find query.
  How can i do that ?

Since in your case, object belongs to the class of your model where you have defined attr_accessor attribute. All you have to do is just say @object_name.attribute_name = “data you want to display!” in the action you are calling and then same attribute will be available in its template too.