简体   繁体   中英

undefined method to each do Ruby on rails

I have two tables: Dimensions and Task. For each dimension have N task. so in Task Controller i have this:

def new
  @dimensions =  Dimension.all
  @dimensions.each do |dimension|
    @task = Task.new
  end
end 

and the view Task this

<h1>Tasks#new</h1>
<%= form_for(@task) do |task| %>
  <div class='service'>
    <li class="col-md-3">
      <div class="thumbnail">
        <div class="caption">
          <h4><%= task.name %></h4>
          <p><%= task.description %></p>
        </div>
        <span>
        </span>
      </div>
    </li>
  </div>
<% end %>

but on the task view it shows me this error message

undefined method 'name'

undefined method 'descripcion'

try this,

def new
  @dimensions =  Dimension.all
  @dimensions.each do |dimension|
    @task = dimension.tasks.new //OR @task = dimension.build_tasks
  end
end 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM