没有路线匹配 [POST] “/portfollios/new”
No route matches [POST] "/portfollios/new"
大家好,我遇到了问题,没有路由匹配,尽管我已经创建了 new
和 create
方法。
portfollios_controller.rb
class PortfolliosController < ApplicationController
def index
@portfolio_items = Portfollio.all
end
def new
@portfolio_item = Portfollio.new
end
def create
@portfolio_item = Portfollio.new(params.require(:portfollio).permit(:title, :subtitle, :body))
respond_to do |format|
if @portfolio_item.save
format.html { redirect_to portfollio_path, notice: 'Your portfolio item is now live.' }
else
format.html { render :new }
end
end
end
end
routes.rb
Rails.application.routes.draw do
resources :portfollios
end
new.html.erb
<h1>Create a new Portfolio Item</h1>
<%= form_with(model: @portfolio_items, local: true) do |form| %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :subtitle %>
<%= form.text_field :subtitle %>
</div>
<div class="field">
<%= form.label :body %>
<%= form.text_area :body %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
谁能帮我解决这个问题。我想不通。
我明白了。问题出在文件 new.html.erb
我需要更改以下行:-
<%= form_with(model: @portfolio_items, local: true) do |form| %>
至
<%= form_with(model: @portfolio_item, local: true) do |form| %>
应该是@portfolio_item不是复数。
大家好,我遇到了问题,没有路由匹配,尽管我已经创建了 new
和 create
方法。
portfollios_controller.rb
class PortfolliosController < ApplicationController
def index
@portfolio_items = Portfollio.all
end
def new
@portfolio_item = Portfollio.new
end
def create
@portfolio_item = Portfollio.new(params.require(:portfollio).permit(:title, :subtitle, :body))
respond_to do |format|
if @portfolio_item.save
format.html { redirect_to portfollio_path, notice: 'Your portfolio item is now live.' }
else
format.html { render :new }
end
end
end
end
routes.rb
Rails.application.routes.draw do
resources :portfollios
end
new.html.erb
<h1>Create a new Portfolio Item</h1>
<%= form_with(model: @portfolio_items, local: true) do |form| %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<div class="field">
<%= form.label :subtitle %>
<%= form.text_field :subtitle %>
</div>
<div class="field">
<%= form.label :body %>
<%= form.text_area :body %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
谁能帮我解决这个问题。我想不通。
我明白了。问题出在文件 new.html.erb
我需要更改以下行:-
<%= form_with(model: @portfolio_items, local: true) do |form| %>
至
<%= form_with(model: @portfolio_item, local: true) do |form| %>
应该是@portfolio_item不是复数。