Topic: Beginner's:Return database records in ruby


How do we deal with database entries in ruby?
I wanted to return a list of records from a model func to controller. Please help me.

Last edited by cybercoder (2012-06-04 21:02:32)

Re: Beginner's:Return database records in ruby

When starting something new, always, always, always start with the documentation. In other words RTFM. will answer all your questions to start with. Go through EVERYTHING on that page. you will find the answer to your question in section 6.7 which shows an index action for a posts ontroller retrieving all the posts records for an index page

def index
  @posts = Post.all

  respond_to do |format|
    format.html  # index.html.erb
    format.json  { render :json => @posts }

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Beginner's:Return database records in ruby

I can advice railsforzombies site. It's good for novice and not so boring smile
PS: Try to be more concrete(add current code) if you want appropriate advices.