2016-07-08 3 views
0

두 가지 모델, 즉 할일과 할 일이 있습니다. Has_many, Belongs_to 사이에 assosciation을 설정하십시오 (todo에는 많은 작업이 있고 task는 todo에 속합니다).중첩 된 리소스 레일

<%= form_for([@todo, @task], html:{class:'form-horizontal'}) do |f| %> 
    <% if @task.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@task.errors.count, "error") %> prohibited this todo from being saved:</h2> 

     <ul> 
     <% @task.errors.full_messages.each do |message| %> 
     <li><%= message %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <script type="text/javascript"> 
    $(document).ready(function() { 
      $('#datep').on('change', function() { 
      $('.datepicker').hide(); 
     }); 

    }); 
    </script> 

    <div class="container"> 
     <table style="width:70%" class="table"> 
     <tr> 
      <td><%= f.label :title , "Task Title"%> 
      <%= f.text_field :title,:class=>'form-control input-sm' %></td> 
     </tr> 

     <tr> 
      <td><%= f.label :description,"Task Description"%> 
      <%= f.text_field :description,:class=>'form-control input-sm' %></td> 
     </tr> 

     <tr> 
      <td><%= f.label :deadline,"Task DeadLine"%> 
      <h id="datep"><%= f.text_field :deadline, :class=>'form-control input-sm', "data-provide" => "datepicker" ,"data-date-format" => "mm-dd-yyyy"%></h></td> 
     </tr> 

     <tr> 
      <td><%= f.label :assignee,"Task Assignee" %><br/> 
      <%= f.collection_select :assignee, User.all, :name, :name, {}, :class => "btn btn-default dropdown-toggle"%></td> 
     </tr> 

     <tr> 
      <td><%= f.label :tags,"Tags for Task"%> 
      <%= f.text_field :tags,:class=>'form-control input-sm' %></td> 
     </tr> 

     <tr> 
      <td><%= f.label :state,"Task Status"%><br/> 
      <%= f.select :state, ['Yet To Start', 'In Progress', 'Finished'], {}, :class => "btn btn-default dropdown-toggle"%></td> 
     </tr> 

    </table> 
    </div> 

    <br /> 
    <div class="actions form-group"> 
    <div class="container"> 
    <%= f.submit 'Create New Task', class:'btn btn-success'%> 
    &nbsp;&nbsp; 
    <%= link_to todos_path, class: 'btn btn-warning' do %> 
     <i class="glyphicon glyphicon-hand-left"></i> Back To List 
    <% end %> 
    </div> 

    </div> 
    <% end %> 

내 작업 컨트롤러 코드는 다음과 같습니다

내 경로가

resources :todos do 
    resources :tasks 
    end 

파일 새 작업을 만들기위한 나의 양식은 아래와 같습니다에 아래 그림과 같이 그들 사이에 중첩 된 자원을 설정 한 아래에 표시됩니다.

그러나 특정 할 일에 새 작업을 추가하려는 경우 이 오류 메시지가 표시된다

undefined method `tasks_path' for #<#<Class:0x007fd16a9c8810>:0x007fd169c95a80> 
Did you mean? asset_path 

내가 뭘 잘못 알고있는 데 도움이 필요합니까 ???

답변

0

redirect_to은 해시, 레코드 또는 문자열 만 허용하므로 redirect_to [@todo, @task]이 작동하지 않습니다. http://api.rubyonrails.org/classes/ActionController/Redirecting.html을 참조하십시오. 여기를 적당히 redirect_to todo_tasks_path(@todo)으로 변경할 수 있습니다.

컨트롤러에 before_filter :set_todo을 넣지 않은 것으로 나타났습니다. 더 이상 필요하지 않은 create 작업에서 @todo = Todo.find.(params[:todo_id])을 삭제할 수 있습니다.

희망이 있습니다.

+0

버튼을 클릭하여 새 작업을 만들면 양식이 첫 번째 위치에 표시되지 않습니다. 대신 오류가 표시됩니다. 그래서 내가 거기에 뭔가를 생각하고 html 양식을 – AKKI

+0

그건 정말 매력처럼 작동했습니다, 고마워요 많은 친구 – AKKI