4

사용자가 시리즈를 만든 다음 시리즈의 에피소드를 만든 다음 각 에피소드에 대한 여러 링크를 만들 수있는 간단한 앱을 만들고 있습니다. Cocoon 보석을 사용해 보았지만보기에 표시 할 수 없었습니다.param is missing 또는 값이 비어 있습니다. series

나는 모든 것을 올바르게 설정했다고 생각했지만 누군가 내가 내가 잘못했거나 누락 된 것을 찾도록 도와 줄 수 있기를 바랍니다. 감사합니다!

나는이 오류가 무엇입니까 : param is missing or the value is empty: series

그리고 콘솔에서

:

Processing by SeriesController#update as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"KAF06O/2C3EBRwos7UnJGSzWF2SGVVB7YdrNnuWt0M=", "commit"=>"Update Series", "id"=>"2"}        
Series Load (0.2ms) SELECT "series".* FROM "series" WHERE "series"."id" = ? LIMIT 1 [["id", "2"]]                 
Completed 400 Bad Request in 39ms 

ActionController::ParameterMissing (param is missing or the value is empty: series):                     
    app/controllers/series_controller.rb:64:in `series_params' 
    app/controllers/series_controller.rb:35:in `block in update' 
    app/controllers/series_controller.rb:34:in `update' 

이들은 내 모델이 어떻게 생겼는지 :

# app/models/series.rb 
class Series < ActiveRecord::Base 
    has_many :episodes 
    accepts_nested_attributes_for :episodes 
end 

# app/models/episode.rb 
class Episode < ActiveRecord::Base 
    belongs_to :series 
    has_many :links 
    accepts_nested_attributes_for :links 
end 

# app/models/link.rb 
class Link < ActiveRecord::Base 
    belongs_to :episode 
end 

내 컨트롤러 :

class SeriesController < ApplicationController 

    before_action :set_series, only: [:show, :edit, :update, :destroy, :links] 

    def new 
    @series = Series.new 
    @series.episodes.build 
    end 

    def update 
    respond_to do |format| 
     if @series.update(series_params) 
     format.html { redirect_to @series, notice: 'Series was successfully updated.' } 
     format.json { render :show, status: :ok, location: @series } 
     else 
     format.html { render :edit } 
     format.json { render json: @series.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # ... ignoring content that hasn't changed from scaffold 

    def links 
    @episodes = @series.episodes 
    end 

    private 
    def series_params 
    params.require(:series).permit(:name, 
     episodes_attributes: [:id, :title, 
     links_attributes: [:id, :url] 
     ]) 
    end 
end 

견해 파일 :

<!-- app/views/series/links.html.erb --> 
<h1><%= @series.name %></h1> 

<%= form_for(@series) do |f| %> 
    <table> 
    <thead> 
     <tr> 
     <td>Title</td> 
     <td>Season</td> 
     <td>Episode</td> 
     </tr> 
    </thead> 
    <tbody> 
     <% @episodes.each do |episode| %> 
     <tr> 
     <td><%= episode.title %></td> 
     <td><%= episode.season %></td> 
     <td><%= episode.episode %></td> 
     <td> 
     <%= f.fields_for :episodes, episode.build do |e| %> 
      <%= e.fields_for :links, episode.link.build do |a| %> 
      <%= a.text_area :url %> 
      <% end %> 
     <% end %> 
     </td> 
     </tr> 
     <% end %> 
    </tbody> 
    </table> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

그리고 경로 파일 :

#app/controllers/series_controller.rb 
def new 
    @series = Series.new 
    @series.episodes.build.links.build #-> creates one link object you can populate 
end 

그런 다음 당신이 당신의 양식을 변경해야합니다 : 당신은 너무 당신의 연결을 구축 할 필요가

MyApp::Application.routes.draw do 

    resources :series do 
    member do 
     get 'links' 
    end 
    end 

end 
+1

이 SeriesController 및 예외를 발생시킨 뷰에서'update' 조치를 게시, 공급에는'series'가 없다 보기에서 'update' 액션은 예외를 일으키는'series_params'를 사용합니다 – bjhaid

+0

@bjhaid 방금 정보로 질문을 업데이트했습니다. 제발보십시오 – crentist

+0

당신은 아마도 당신의보기에서'@ 에피소드'를 바꾸고 싶을 것입니다 'f.episodes'로, 내부 루프는 블록을 바인딩하는 변수를 가리키고'f'는 가리 키지 않습니다. – bjhaid

답변

0

작성된 링크 개체를 사용하려면

<%= f.fields_for :episodes do |e| %> 
     <%= e.fields_for :links do |a| %> 
     <%= a.text_area :url %> 
     <% end %> 
    <% end %> 

이렇게하면 new & create 동작이 작동합니다. 그러나 update 작업에 대한 로그를 게시했습니다. create 또는 update과 관련된 문제가 있습니까?

1

나는 일련의 매개 변수 당신이 params.require(:series).permit을 같이 사용하고 있다는 점에서 series_params 방법을 사용하는 액션에보기

Parameters: {"utf8"=>"✓", "authenticity_token"=>"KAF06O/2C3EBRwos7UnJGSzWF2SGVVB7YdrNnuWt0M=", "commit"=>"Update Series", "id"=>"2"}        

에서 통과되지 않는다 생각합니다.

은 그래서 당신이보기 또는 전달 파일을 볼 수에 확인하시기 바랍니다

param is missing or the value is empty: series을 던지고하지