2016-04-28 9 views
1

Ich habe mir andere Antworten angesehen und bekomme immer noch diesen Fehler, wenn die Parameter fehlen. Ich vermute, es handelt sich um eine Büroklammer, aber nachdem ich die Dokumente durchsucht habe, kann ich nichts finden, was dieses Problem löst.Fehler/Fehler: click_button "Film hinzufügen" ActionController :: ParameterMissing: Parameter fehlt oder der Wert ist leer: Film

Meine Eigenschaften Spezifikation

scenario "An Admin creates a new movie" do 
     visit "/" 
    click_link "Add New Movie"``` 

    fill_in "Title", with: "Creating first movie" 
    fill_in "Synopsis", with: "Lorem Ipsum" 
    fill_in "Year Released", with: "Date" 
    click_button "Add Movie" 

    expect(page).to have_content("Movie has been created") 
    expect(page.current_path).to eq(root_path) 
    expect(page).to have_content("Created by: #{@kyle.email}")``` 

end 

Mein Film Modell

class Movie < ApplicationRecord 
    has_many :comments 
    belongs_to :admin 

    validates :title, presence: true 
    validates :synopsis, presence: true 
    validates :year_released, presence: true 

    has_attached_file :photo, styles: { medium: "300x200>", thumb: "100x100>" },   default_url: "/images/:style/missing.png" 

validates_attachment_file_name: Foto, Spiele: [?/Png \ Z /,/jpe g \ Z /] `` `

My-Controller

def update 
    if @movie.update(movie_params) 
    flash[:success] = "Movie has been updated" 
    redirect_to @movie 
    else 
    flash.now[:danger] = "Movie has not been updated" 
    render :edit 
    end 
end 

private 

def movie_params 
    params.require(:movie).permit(:title, :synopsis, :year_released, :photo) 
end 

Mein _form.html.erb

<div class="form-group"> 
    <div class='control-label col-md-3'> 
    <%= f.label :photo %> 
    </div> 
    <div class='col-md-10'> 
    <%= f.file_field :photo, class: "btn btn-primary btn-sl pull-left" %> 
    </div> 

<div class='form-group'> 
<div class='col-md-offset-1 col-md-11'> 
    <%= f.submit "Add Movie", class: "btn btn-primary btn-lg pull-right" %> 
</div> 

Der Fehler

Failure/Error: click_button "Add Movie" 
ActionController::ParameterMissing: 
param is missing or the value is empty: movie``` 

Mein Github wenn nötig.

+0

wie ist Ihr form_for wie – uzaif

+0

aussehen '' '<% = form_for (@movie)%> <% = f.label: title%> <% = f.text_field: Titel, Klasse:‚Form-control ', Platzhalter:' Titel des Films ', Autofokus: true%> <% = f.label: Synopsis%> <% = f.text_area: Übersicht, Zeilen: 10, Klasse:' Formularsteuerung ', Platzhalter: 'Übersicht'%> <% = f.label: Foto%> <% = f.file_field: Foto, Klasse: "btn btn-primärer btn-sl pull-left"%> '' ' – kyle

+0

Fehler beim Aktualisieren Film? – uzaif

Antwort

0

Ich gehe davon aus, dass Sie require in strong_params verwenden.

änderte ich Ihren Code

def movie_params 
    params.fetch(:movie, {}).permit(:title, :synopsis, :year_released, :photo) 
end 

und bestandenen Tests.

[[email protected] ~/temp/moviesmoviesmovies]$ git:(development) rspec spec/features/creating_movies_spec.rb 
DEPRECATION WARNING: use_transactional_fixtures= is deprecated and will be removed from Rails 5.1 (use use_transactional_tests= instead). (called from <top (required)> at /Users/retgoat/temp/moviesmoviesmovies/spec/features/creating_movies_spec.rb:3) 
.. 

Finished in 0.73751 seconds (files took 1.91 seconds to load) 
2 examples, 0 failures 

Auch ich versuchte es im Browser alles ging wie erwartet - ich sah Validierungsfehler.

Dokumentation ist here

Auch that Post war nützlich.

+0

Super! Vielen Dank! retgoat – kyle

+0

Willkommen, @ kyle :) – retgoat