【发布时间】:2021-01-11 21:44:46
【问题描述】:
提交表单时出现路由错误
resources :sellers do
resources :seller_profiles
end
<%= form_for seller_seller_profiles_path do |form| %>
<div class="field">
<%= form.label :first_name %>
<%= form.text_field :first_name %>
</div>
<div class="field">
<%= form.label :other_name %>
<%= form.text_field :other_name %>
</div>
-- more similar fields ---
<div class="actions">
<%= form.submit %>
</div>
<% end %>
def create
@seller_profile = @seller.seller_profile.create!(seller_profile_params)
respond_to do |format|
format.html { redirect_to root_path}
end
错误信息: 于 2021-01-11 21:37:01 +0000 开始为 ::1 发布“/sellers/1/seller_profiles/new”
ActionController::RoutingError(没有路由匹配 [POST] "/sellers/1/seller_profiles/new"):
更新
我把视图改为
<%= form_with(model: [@seller, @seller_profile], local: true) do |form| %>
--- code continues ---
现在新路由可以工作,但编辑路由会抛出此错误 ActionView::Template::Error (undefined method `seller_profile_path' for #ActionView::Base:0x0000000001d060 你的意思是?卖家路径):
【问题讨论】:
-
该新错误可能与该视图附带的按钮之一有关,您可能需要更新路径。
标签: ruby-on-rails