【发布时间】:2017-04-21 14:17:59
【问题描述】:
# Here's the error I am getting when trying to load my partial:
`ActionController::UrlGenerationError - No route matches {:action=>"update", :controller=>"queries"}:`
# Here's the form I am trying to load within a partial on the `queries/1/edit` page:
`<%= form_for @query, url: {action: 'update'}, method: :put do |f| %>`
# Here's my controller:
def update
@query = Query.find(params[:query])
if @query.update(query_params)
redirect_to queries_path, notice: 'Saved query successfully!'
else
redirect_to edit_query_path, alert: @query.errors.full_messages
end
end
# Route:
resources :queries
我尝试将 @query => 1 和 @query => Query.find_by_id(1) 和 @query => Query.find(params[:query_id]) 传递给部分,但仍然收到“没有路由匹配更新”错误。
我试过<%= form_for(@query) do |f| %>而不是url方式,但得到这个错误QueriesController#MY_PARTIAL is missing a template for this request format and variant.
请帮我解开 =) Rails 5.0.1, ruby 2.3.0p0
【问题讨论】:
-
<%= form_for @query do |f| %>通常只要在您的路线中设置正确就足够了。 -
@Iceman 是的,当这不起作用时我很惊讶。我正在提交
form_for来自已正确链接到控制器的关注文件深处的路由,所以我认为可能需要更多规范? -
你是如何渲染这个局部的?
-
$("#query-builder").hide().html("<%= escape_javascript(render 'queries/layer_5') %>").fadeIn(500);这个js是通过提交form_tag触发的 -
@Iceman 已解决/已编辑。感谢您的帮助!
标签: ruby-on-rails forms routes