Ruby on rails 没有与[POST]匹配的路线”/组织/新;
在我的rails应用程序中,我获得了很多资源,并且已经创建了一些表单——但由于某些原因,我似乎没有为新对象提供一个特定的表单。我不确定这是因为我使用了三种方法:通过关系还是因为我忽略了其他东西 我的路线是这样的Ruby on rails 没有与[POST]匹配的路线”/组织/新;,ruby-on-rails,Ruby On Rails,在我的rails应用程序中,我获得了很多资源,并且已经创建了一些表单——但由于某些原因,我似乎没有为新对象提供一个特定的表单。我不确定这是因为我使用了三种方法:通过关系还是因为我忽略了其他东西 我的路线是这样的 resources :users, shallow: true do resources :organizations, :notifications end resources :organizations, shallow: true do resour
resources :users, shallow: true do
resources :organizations, :notifications
end
resources :organizations, shallow: true do
resources :plans, :users, :notifications
end
我的组织\u控制器如下所示:
def index
@user = current_user
@organizations = @user.organizations.to_a
end
def show
@user = current_user
@organization = Organization.find(params[:id])
end
def new
@organization = Organization.new
end
def create
@user = current_user
@organization = Organization.new(organization_params)
@organization.save
redirect_to @organization
end
在“我的组织索引”页面上,我链接到:
<%= button_to 'New Organization', new_organization_path, :class => 'btn btn-primary' %>
这是正确的-我没有接受POST请求的新路径。我知道我可以手动更改表单的方法以获取,但它不应该像我那样工作吗?我有另一种形式,它遵循相同的原则,只针对不同的资源,并且工作得非常完美
提前谢谢你的帮助
按钮\u to
将始终发送POST
请求,除非指定了其他内容。
在另一个表单上,您必须使用链接到
,而不是按钮到
,这就是它在那里工作的原因
您可以通过两种方式将按钮更改为,选择一种适合您的方式:
选项1:使用链接_
“btn btn主节点”%>
选项2:使用按钮_与方法::get一起使用
“btn btn主节点”%>
从现在起,你就是我的个人英雄。我知道这很简单,于是花了好几个小时想弄明白!呵呵……很乐意帮忙:)
<%= form_for (@organization) do |f| %>
<%= render 'layouts/messages' %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :website %>
<%= f.text_area :website, class: 'form-control' %>
</div>
<%= f.button :class => 'btn btn-primary' %>
<% end %>
No route matches [POST] "/organizations/new"
<%= link_to 'New Organization', new_organization_path, :class => 'btn btn-primary' %>
<%= button_to 'New Organization', new_organization_path, method: :get, :class => 'btn btn-primary' %>