Controller / irb

This is my controller:

class Members < ActiveRecord::Base   def name     return name + ""   end

def describe   return name + "" + email + "" + mobile + "" + category + "" + other end end

when i go into the rails console and connect to Members, I say:

a = Members.first

a.name <<< this should give me the "name" of that person but it does not, it says:

SystemStackError: stack level too deep

That is because your name method is called recursively - the `return name + ""` is calling `name` once again and again and again... If you want to access raw attributes from database on ActiveRecord models, you can always use `self[:name]`.

It might be convenient for you to use ruby interpolations in a method like `describe`. The following is equivalent to your method (you don't need return either - the last thing evaluated is always returned from a method):

def describe    "#{name}#{email}#{mobile}#{category}#{other}" end

I don't understand the idea behind `+ ""`. If you want convert any value to string, it is convention in ruby to call #to_s method on it. If you use anything in an interpolation, ruby will call #to_s on this object for you.

Michał.

Muskalek wrote in post #1158351: That is because your name method is called recursively - the `return name + ""` is calling `name` once again and again and again... If you want to access raw attributes from database on ActiveRecord models, you can always use `self[:name]`.

It might be convenient for you to use ruby interpolations in a method like `describe`. The following is equivalent to your method (you don't need return either - the last thing evaluated is always returned from a method):

def describe    "#{name}#{email}#{mobile}#{category}#{other}" end

I don't understand the idea behind `+ ""`. If you want convert any value to string, it is convention in ruby to call #to_s method on it. If you use anything in an interpolation, ruby will call #to_s on this object for you.

Michał.

Thank you very much for your help sir :slight_smile:

Thank you Michal, your post is at must help, however I have discovered a new gem called fullcalendar. Do you think that with this, you can link these id's so that we can view each attribute in a calendar. So basically like the day will be on the left but then I will be able to display this persons "#{name}#{email}#{mobile}#{category}#{other}" also on the calendar.?