Ruby on rails 没有路由匹配{:action=>;“;show”;..}访问新操作时缺少必需的键:[:id]?
为什么在我尝试访问新动作时会发生这种情况 routes.rbRuby on rails 没有路由匹配{:action=>;“;show”;..}访问新操作时缺少必需的键:[:id]?,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,为什么在我尝试访问新动作时会发生这种情况 routes.rb resources :tvseries class TvseriesController < ApplicationController before_action :set_tvseries, only: [:show, :edit, :update, :destroy] # GET /tvseries # GET /tvseries.json def index @tvseries = Tvse
resources :tvseries
class TvseriesController < ApplicationController
before_action :set_tvseries, only: [:show, :edit, :update, :destroy]
# GET /tvseries
# GET /tvseries.json
def index
@tvseries = Tvserie.all
end
# GET /tvseries/1
# GET /tvseries/1.json
def show
end
# GET /tvseries/new
def new
@tvseries = Tvserie.new
end
# GET /tvseries/1/edit
def edit
end
# POST /tvseries
# POST /tvseries.json
def create
@tvseries = Tvserie.new(tvseries_params)
respond_to do |format|
if @tvseries.save
format.html { redirect_to @tvseries, notice: 'Tvserie was successfully created.' }
format.json { render :show, status: :created, location: @tvseries }
else
format.html { render :new }
format.json { render json: @tvseries.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /tvseries/1
# PATCH/PUT /tvseries/1.json
def update
respond_to do |format|
if @tvseries.update(tvseries_params)
format.html { redirect_to @tvseries, notice: 'Tvserie was successfully updated.' }
format.json { render :show, status: :ok, location: @tvseries }
else
format.html { render :edit }
format.json { render json: @tvseries.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tvseries/1
# DELETE /tvseries/1.json
def destroy
@tvseries.destroy
respond_to do |format|
format.html { redirect_to tvseries_url, notice: 'Tvserie was successfully destroyed.' }
format.json { head :no_content }
end
end
# GET /all_tv_series
def all
@tv_series = Tvserie.all
end
# GET /tv_series/add_language/1
# GET /tv_s/add_language/1.json
def add_subtitles
@languages = Language.all
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tvseries
@tvseries = Tvserie.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def tvseries_params
params.require(:tvseries).permit(:title, :image, :description)
end
end
<%= form_for(@tvseries) do |f| %>
<% if @tvseries.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tvseries.errors.count, "error") %> prohibited this tvseries from being saved:</h2>
<ul>
<% @tvseries.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :image %><br>
<%= f.text_field :image %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
tvseries\u控制器.rb
resources :tvseries
class TvseriesController < ApplicationController
before_action :set_tvseries, only: [:show, :edit, :update, :destroy]
# GET /tvseries
# GET /tvseries.json
def index
@tvseries = Tvserie.all
end
# GET /tvseries/1
# GET /tvseries/1.json
def show
end
# GET /tvseries/new
def new
@tvseries = Tvserie.new
end
# GET /tvseries/1/edit
def edit
end
# POST /tvseries
# POST /tvseries.json
def create
@tvseries = Tvserie.new(tvseries_params)
respond_to do |format|
if @tvseries.save
format.html { redirect_to @tvseries, notice: 'Tvserie was successfully created.' }
format.json { render :show, status: :created, location: @tvseries }
else
format.html { render :new }
format.json { render json: @tvseries.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /tvseries/1
# PATCH/PUT /tvseries/1.json
def update
respond_to do |format|
if @tvseries.update(tvseries_params)
format.html { redirect_to @tvseries, notice: 'Tvserie was successfully updated.' }
format.json { render :show, status: :ok, location: @tvseries }
else
format.html { render :edit }
format.json { render json: @tvseries.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tvseries/1
# DELETE /tvseries/1.json
def destroy
@tvseries.destroy
respond_to do |format|
format.html { redirect_to tvseries_url, notice: 'Tvserie was successfully destroyed.' }
format.json { head :no_content }
end
end
# GET /all_tv_series
def all
@tv_series = Tvserie.all
end
# GET /tv_series/add_language/1
# GET /tv_s/add_language/1.json
def add_subtitles
@languages = Language.all
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tvseries
@tvseries = Tvserie.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def tvseries_params
params.require(:tvseries).permit(:title, :image, :description)
end
end
<%= form_for(@tvseries) do |f| %>
<% if @tvseries.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tvseries.errors.count, "error") %> prohibited this tvseries from being saved:</h2>
<ul>
<% @tvseries.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :image %><br>
<%= f.text_field :image %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
模式
create_table "tvseries", force: :cascade do |t|
t.string "title"
t.text "description"
t.string "image"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
问题在于命名约定 Tvseries可用于单数和复数形式
您应该将您的型号名称改为
Tvseries
而不是Tvserie
您可以显示您试图打开Tvseries/新路径的链接标签吗?它是
,但它太奇怪了,我还有其他型号和控制器,如电影或动画,我可以在浏览器上或通过链接进入电影/新或动画/新,但tvseries在这两方面都失败了。我们能看到整个表单吗?@tvseries的表单似乎抛出了UrlGeneration错误我编辑了帖子,表单现在就在那里