Hi, I was reading about ActiveModel to ride rails without ActiveRecord, but the documentation doesn''t include info about find, and how to implement search functionality. I need to do the following: - i have a simple controller which get 2 parameters (:country, :city) - i would like to implement a simple search which returns the population of the city Controller code: @country = params[:country] @city = params[:city] @population = Population.find(:country => @country, :city => @city) How should I implement find in the model? The data is in plain text files(don''t ask), and I can look up in it using country_city as key and the population as value (simple hash). Thank you in advance, Istvan -- 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.
On Mar 8, 2011, at 8:58 AM, lix wrote:> Hi, > > I was reading about ActiveModel to ride rails without ActiveRecord, > but the documentation doesn''t include info about find, and how to > implement search functionality. > > I need to do the following: > > - i have a simple controller which get 2 parameters (:country, :city) > - i would like to implement a simple search which returns the > population of the city > > Controller code: > > @country = params[:country] > @city = params[:city] > @population = Population.find(:country => @country, :city => @city) > > How should I implement find in the model? The data is in plain text > files(don''t ask), and I can look up in it using country_city as key > and the population as value (simple hash).The fetch method will return the value from a given key in a hash. http://corelib.rubyonrails.org/classes/Hash.html#M000689 Walter> > Thank you in advance, > Istvan > > -- > 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 > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Mar 8, 2011 at 2:58 PM, lix <leccine-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was reading about ActiveModel to ride rails without ActiveRecord, > but the documentation doesn''t include info about find, and how to > implement search functionality. > > I need to do the following: > > - i have a simple controller which get 2 parameters (:country, :city) > - i would like to implement a simple search which returns the > population of the city > > Controller code: > > @country = params[:country] > @city = params[:city] > @population = Population.find(:country => @country, :city => @city) > > How should I implement find in the model? The data is in plain text > files(don''t ask), and I can look up in it using country_city as key > and the population as value (simple hash).Perhaps you don''t even need Active Model? -- 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.
So just to answer my question:
def self.find(key)
return @h[key]
end
Where h is the hash I have created from the file.
Thanks all,
I.
On Mar 8, 1:58 pm, lix <lecc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I was reading about ActiveModel to ride rails without ActiveRecord,
> but the documentation doesn''t include info about find, and how to
> implement search functionality.
>
> I need to do the following:
>
> - i have a simple controller which get 2 parameters (:country, :city)
> - i would like to implement a simple search which returns the
> population of the city
>
> Controller code:
>
> @country = params[:country]
> @city = params[:city]
> @population = Population.find(:country => @country, :city => @city)
>
> How should I implement find in the model? The data is in plain text
> files(don''t ask), and I can look up in it using country_city as
key
> and the population as value (simple hash).
>
> Thank you in advance,
> Istvan
--
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.