ruby - rails relationship. Rails 4 -


i'm new in world of rails developers. please, me understand. i've 3 tables: calls, questions, results

calls is: id, name, date

questions is: id, question

results is: id, call_id, question_id, result

i've read rails manual, understand i've created 3 models.

in model call.rb i've done next relationship:

has_many   :results has_many   :question, through: :results 

my result.rb

belongs_to :call belongs_to :question 

my question.rb

has_many :result 

so, there can many records in table "results" 1 call_id, , it's can 1 relation question through results table

if if try launch code this:

@calls = call.all 

than on view:

<% @calls.each |call| %> <%= call.result.result %> <% end %> 

i've error "result undefined method". it's must property.

what wrong? thanks!

according schema, associations should this

class call < activerecord::base   has_many :questions   has_many :results end  class question < activerecord::base   belongs_to :call end  class result < activerecord::base   belongs_to :call end 

so in view,

<% @calls.each |call| %>   <% call.results.each |result| %>     <%= result.result%>   <% end %> <% end %> 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -