Forum: Ruby on Rails Beginner's:Return database records in ruby

Acbbc20c6066e691a11755d97311082e?d=identicon&s=25 cyber c. (cyber_c)
on 2012-06-05 02:02
Hi,

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.
955103d80e386882143a78875fb727bf?d=identicon&s=25 Jeremy W. (jeremy_w)
on 2012-06-05 03:20
(Received via mailing list)
On 5 June 2012 01:02, cyber c. <lists@ruby-forum.com> wrote:

> def self.get_all_pairs
> //LOGIC
> end
>
> i get an error undefined method 'name' for ".":String
> in line -> <td><%=data_pair.name %></td>
>

You are expecting data_pair to be an object of type DataPair, with a
name
attribute. However, it's not - it's a string. Maybe you could post a
gist
of the get_app_pairs method and the template and we can help further.
Acbbc20c6066e691a11755d97311082e?d=identicon&s=25 cyber c. (cyber_c)
on 2012-06-05 03:24
Thanks for the reply. But i have changed the message long back ,it
still shows old message.
My actual post was

How do we deal with database records in ruby?
I wanted to return a list of records from a model func to controller.
Please help me.
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-06-05 10:21
(Received via mailing list)
On 5 June 2012 01:02, cyber c. <lists@ruby-forum.com> wrote:
> def self.get_all_pairs
> //LOGIC
> end
>
> i get an error undefined method 'name' for ".":String
> in line -> <td><%=data_pair.name %></td>
>
> Im a beginner in ROR. Can someone help me out ?

Have a look at the Rails Guide on Debugging for techniques you can use
to debug your code.  Also you say that you are a beginner.  If you
have not already done so then work right through some tutorials on
Rails.  railstutorial.org is good and is free to use online.

Colin
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-06-05 10:24
(Received via mailing list)
On 5 June 2012 02:24, cyber c. <lists@ruby-forum.com> wrote:
> Thanks for the reply. But i have changed the message along back but it
> still shows old message.
> My actual post was
>
> How do we deal with database records in ruby?
> I wanted to return a list of records from a model func to controller.
> Please help me.

As I said in reply to your previous post work through some tutorials
such as railstutorial.org.  These will give you a grasp of the
fundamentals of Rails.

Colin
C3ff8ba613f2dc50cc30e7f3af3e2914?d=identicon&s=25 Will C (Guest)
on 2012-06-05 22:13
(Received via mailing list)
I'm not sure if this fixes your problem but anyone can correct me if I'm
wrong -- I think when you call DataPair.all you get an array of all the
DataPairs so essentially you should be doing this after:

<? @data_par.each do |data_pair| ?>
  <td><?= data_pair.name ?></td>
<? end ?>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.