Rails 4: ActionController::ParameterMissing 参数缺失或值为空:youtube_vid
Rails 4: ActionController::ParameterMissing param is missing or the value is empty: youtube_vid
好的伙计们,
我不知道为什么我的 new/create 操作现在给我带来麻烦,但我收到以下错误。关于为什么的任何想法?提前谢谢你。
ActionController::ParameterMissing in ArtistYoutubeVideosController#create
param is missing or the value is empty: youtube_vid
它突出显示了这些代码行:
def create
@youtube_vid = ArtistYoutubeVideo.new(youtube_vid_params)
if @youtube_vid.save
redirect_to artist_youtube_videos_path
else
render :new
end
end
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
参数:
{"utf8"=>"✓",
"authenticity_token"=>"HGnaAPOrw8Fbz7/dR12GXRoo6ZWByCbqN5L15C0D5yxBlpLy0afRkVaJ1peJkt1pB+tqZaytgJPJTNPoEl54yg==",
"artist_youtube_video"=>{"video_name"=>"test 11",
"video_url"=>"test 11"},
"commit"=>"Submit"}
ArtistYoutubeVideosController.rb
class ArtistYoutubeVideosController < ApplicationController
def index
@youtube_vids = ArtistYoutubeVideo.all
end
def new
@youtube_vid = ArtistYoutubeVideo.new
end
def create
@youtube_vid = ArtistYoutubeVideo.new(youtube_vid_params)
if @youtube_vid.save
redirect_to artist_youtube_videos_path
else
render :new
end
end
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
end
artist_youtube_videos/new.html.erb
<h1>New Youtube Vids</h1>
<%= form_for(@youtube_vid) do |f| %>
<%= f.label :video_name %>
<%= f.text_field :video_name %>
<%= f.label :video_url %>
<%= f.text_field :video_url %>
<%= f.submit "Submit" %>
<% end %>
schema.rb
create_table "artist_youtube_videos", force: :cascade do |t|
t.string "video_name"
t.text "video_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
routes.rb
resources :artist_youtube_videos
根据您发布的参数,更改
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
到
def youtube_vid_params
params.require(:artist_youtube_video).permit(:id, :video_name, :video_url)
end
你会好起来的。
好的伙计们,
我不知道为什么我的 new/create 操作现在给我带来麻烦,但我收到以下错误。关于为什么的任何想法?提前谢谢你。
ActionController::ParameterMissing in ArtistYoutubeVideosController#create
param is missing or the value is empty: youtube_vid
它突出显示了这些代码行:
def create
@youtube_vid = ArtistYoutubeVideo.new(youtube_vid_params)
if @youtube_vid.save
redirect_to artist_youtube_videos_path
else
render :new
end
end
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
参数:
{"utf8"=>"✓",
"authenticity_token"=>"HGnaAPOrw8Fbz7/dR12GXRoo6ZWByCbqN5L15C0D5yxBlpLy0afRkVaJ1peJkt1pB+tqZaytgJPJTNPoEl54yg==",
"artist_youtube_video"=>{"video_name"=>"test 11",
"video_url"=>"test 11"},
"commit"=>"Submit"}
ArtistYoutubeVideosController.rb
class ArtistYoutubeVideosController < ApplicationController
def index
@youtube_vids = ArtistYoutubeVideo.all
end
def new
@youtube_vid = ArtistYoutubeVideo.new
end
def create
@youtube_vid = ArtistYoutubeVideo.new(youtube_vid_params)
if @youtube_vid.save
redirect_to artist_youtube_videos_path
else
render :new
end
end
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
end
artist_youtube_videos/new.html.erb
<h1>New Youtube Vids</h1>
<%= form_for(@youtube_vid) do |f| %>
<%= f.label :video_name %>
<%= f.text_field :video_name %>
<%= f.label :video_url %>
<%= f.text_field :video_url %>
<%= f.submit "Submit" %>
<% end %>
schema.rb
create_table "artist_youtube_videos", force: :cascade do |t|
t.string "video_name"
t.text "video_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
routes.rb
resources :artist_youtube_videos
根据您发布的参数,更改
def youtube_vid_params
params.require(:youtube_vid).permit(:id, :video_name, :video_url)
end
到
def youtube_vid_params
params.require(:artist_youtube_video).permit(:id, :video_name, :video_url)
end
你会好起来的。