Reputation: 5982
# 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
I've tried passing in @query => 1
and @query => Query.find_by_id(1)
and @query => Query.find(params[:query_id])
to the partial, but still get the "no route matches update" error.
I've tried <%= form_for(@query) do |f| %>
instead of the url way, but get this error QueriesController#MY_PARTIAL is missing a template for this request format and variant.
Please help me get unstuck =) Rails 5.0.1, ruby 2.3.0p0
Upvotes: 0
Views: 349
Reputation: 5982
So I looked at the form_for
params again and, to my surprise, I saw that id: "1"
was being passed. Thus, I changed the controller to
def update
@query = Query.find_by_id(params[:id])
This now works with <%= form_for(@query) %>
Upvotes: 1