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)
BaseManagedEntity.find(:all,
:select => "b.BaseManagedEntityInternalId,
c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}, s.HealthState,
s.LastModified",
:joins => "as b INNER JOIN #{TABLE_NAMES[label]} as c ON
c.basemanagedentityid = b.basemanagedentityid
INNER JOIN state as s ON b.basemanagedentityid
s.basemanagedentityid",
:conditions => BaseManagedEntity.all_conditions(params,
label),
:order => "s.LastModified DESC",
:group => "b.BaseManagedEntityInternalId, s.HealthState,
s.LastModified, c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}" )
end
DEVICE_NAMES = {"windows" => "NetworkName",
"unix" =>
"NetworkName_360E5A02_BC9E_0000_2614_1972E304088A",
"network" =>
"Name_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"}
DEVICE_IPS = {"windows" => "IPAddress",
"unix" =>
"IPAddress_360E5A02_BC9E_0000_2614_1972E304088A",
"network" =>
"IPAddress_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"}
TABLE_NAMES = {"windows" => "mt_computer",
"unix" =>
"MTV_Computer_0",
"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''] )
end
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.
--
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.
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.
On Fri, Aug 19, 2011 at 2:00 PM, merbivore
<eshwardeep-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 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)
> BaseManagedEntity.find(:all,
> :select => "b.BaseManagedEntityInternalId,
> c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}, s.HealthState,
> s.LastModified",
> :joins => "as b INNER JOIN #{TABLE_NAMES[label]} as c ON
> c.basemanagedentityid = b.basemanagedentityid
> INNER JOIN state as s ON b.basemanagedentityid >
s.basemanagedentityid",
> :conditions => BaseManagedEntity.all_conditions(params,
> label),
> :order => "s.LastModified DESC",
> :group => "b.BaseManagedEntityInternalId, s.HealthState,
> s.LastModified, c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}" )
> end
>
>
> DEVICE_NAMES = {"windows" => "NetworkName",
"unix" =>
> "NetworkName_360E5A02_BC9E_0000_2614_1972E304088A",
> "network" =>
> "Name_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"}
>
> DEVICE_IPS = {"windows" => "IPAddress",
"unix" =>
> "IPAddress_360E5A02_BC9E_0000_2614_1972E304088A",
> "network" =>
> "IPAddress_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"}
>
> TABLE_NAMES = {"windows" => "mt_computer",
"unix" =>
> "MTV_Computer_0",
> "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''] )
> end
>
>
> 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.
>
> --
> 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.
>
>
--
Please consider the environment before printing this email.
Regards,
Surya
--
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.
Yeah, 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 ? On Aug 19, 1:43 pm, Surya <raj.sury...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > > > On Fri, Aug 19, 2011 at 2:00 PM, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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) > > BaseManagedEntity.find(:all, > > :select => "b.BaseManagedEntityInternalId, > > c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}, s.HealthState, > > s.LastModified", > > :joins => "as b INNER JOIN #{TABLE_NAMES[label]} as c ON > > c.basemanagedentityid = b.basemanagedentityid > > INNER JOIN state as s ON b.basemanagedentityid > > s.basemanagedentityid", > > :conditions => BaseManagedEntity.all_conditions(params, > > label), > > :order => "s.LastModified DESC", > > :group => "b.BaseManagedEntityInternalId, s.HealthState, > > s.LastModified, c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}" ) > > end > > > DEVICE_NAMES = {"windows" => "NetworkName", "unix" => > > "NetworkName_360E5A02_BC9E_0000_2614_1972E304088A", > > "network" => > > "Name_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"} > > > DEVICE_IPS = {"windows" => "IPAddress", "unix" => > > "IPAddress_360E5A02_BC9E_0000_2614_1972E304088A", > > "network" => > > "IPAddress_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"} > > > TABLE_NAMES = {"windows" => "mt_computer", "unix" => > > "MTV_Computer_0", > > "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''] ) > > end > > > 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. > > > -- > > 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. > > -- > > Please consider the environment before printing this email. > > Regards, > Surya-- 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.
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. On Fri, Aug 19, 2011 at 2:18 PM, merbivore <eshwardeep-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yeah, > > 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 ? > > On Aug 19, 1:43 pm, Surya <raj.sury...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > > > > > > > On Fri, Aug 19, 2011 at 2:00 PM, merbivore <eshward...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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) > > > BaseManagedEntity.find(:all, > > > :select => "b.BaseManagedEntityInternalId, > > > c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}, s.HealthState, > > > s.LastModified", > > > :joins => "as b INNER JOIN #{TABLE_NAMES[label]} as c ON > > > c.basemanagedentityid = b.basemanagedentityid > > > INNER JOIN state as s ON b.basemanagedentityid > > > s.basemanagedentityid", > > > :conditions => BaseManagedEntity.all_conditions(params, > > > label), > > > :order => "s.LastModified DESC", > > > :group => "b.BaseManagedEntityInternalId, s.HealthState, > > > s.LastModified, c.#{DEVICE_NAMES[label]}, c.#{DEVICE_IPS[label]}" ) > > > end > > > > > DEVICE_NAMES = {"windows" => "NetworkName", "unix" => > > > "NetworkName_360E5A02_BC9E_0000_2614_1972E304088A", > > > "network" => > > > "Name_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"} > > > > > DEVICE_IPS = {"windows" => "IPAddress", "unix" => > > > "IPAddress_360E5A02_BC9E_0000_2614_1972E304088A", > > > "network" => > > > "IPAddress_65AC01F1_F20E_CE0D_42CA_B24D1DE49E5F"} > > > > > TABLE_NAMES = {"windows" => "mt_computer", "unix" => > > > "MTV_Computer_0", > > > "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''] ) > > > end > > > > > 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. > > > > > -- > > > 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. > > > > -- > > > > Please consider the environment before printing this email. > > > > Regards, > > Surya > > -- > 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. > >-- Please consider the environment before printing this email. Regards, Surya -- 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.