Rails Method not available in View -


i strange error. have defined method model

    class rating < activerecord::base    [...]    belongs_to :user   belongs_to :movie    [...]    def to_text     texto = case self.grade             when 0..1 "horrible"             when 2..3 "bad"             when 4..5 "not bad"             when 6..7 "good"             when 8..9 "very good"             when 10 "master piece"             end   end end 

then, on controller, define instance:

@current_user_rating=@movie.ratings.where(:user_id => current_user) 

and find it, works. then, when call method, or property like

<%= @current_user_rating.grade %> <%= @current_user_rating.to_text %> 

i error

undefined method `grade' []:activerecord::relation undefined method `to_text' []:activerecord::relation 

why variable not behaving instance appropriate attributes , methods relation?

it work on console, not on server...

since movie has multiple ratings, @current_user_rating collection of them, if there one. should able rid of errors calling methods this:

<% @current_user_rating.each |rating| %>   <%= rating.grade %>   <%= rating.to_text %> <% end %> 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -