Hi, I wanted to populate the DB with (name,data) pairs based on some rules. I have created a scaffold with name and data as attributes. In the controller file under the def for index, i have changed the line @data_pairs = DataPair.all to @data_pairs = DataPair.get_all_pairs and in the corresponding models file i have defined this function 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 ? -- Posted via http://www.ruby-forum.com/. -- 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 5 June 2012 01:02, cyber c. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I wanted to populate the DB with (name,data) pairs based on some rules. > I have created a scaffold with name and data as attributes. In the > controller file under the def for index, i have changed the line > @data_pairs = DataPair.all to > @data_pairs = DataPair.get_all_pairs > > and in the corresponding models file i have defined this function > > 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.> > Im a beginner in ROR. Can someone help me out ? > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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. > >-- 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.
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. -- Posted via http://www.ruby-forum.com/. -- 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 5 June 2012 01:02, cyber c. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I wanted to populate the DB with (name,data) pairs based on some rules. > I have created a scaffold with name and data as attributes. In the > controller file under the def for index, i have changed the line > @data_pairs = DataPair.all to > @data_pairs = DataPair.get_all_pairs > > and in the corresponding models file i have defined this function > > 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 -- 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 5 June 2012 02:24, cyber c. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 -- 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.
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 ?> On Monday, June 4, 2012 8:02:15 PM UTC-4, Ruby-Forum.com User wrote:> > Hi, > > I wanted to populate the DB with (name,data) pairs based on some rules. > I have created a scaffold with name and data as attributes. In the > controller file under the def for index, i have changed the line > @data_pairs = DataPair.all to > @data_pairs = DataPair.get_all_pairs > > and in the corresponding models file i have defined this function > > 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 ? > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AqfyRi1bO8kJ. 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.