0

I have a partial form that creates a post that is being rendered on it's parent model communities, however, it doesn't post the form to this path:

POST   /communities/:community_id/posts(.:format)  posts#create

Instead, it will try posting to the path it's rendered on. For example, No route matches [POST] "/communities/1" because I have the form on a community page.

This is running Rails 6 beta.

I believe a solution would be to specify the path for where it sends to in the form, but I cannot find anything in the documentation that matches that. Either I'm reading wrong, or it's a nonexistent solution and requires a different approach. I'm really not sure.

posts/_form.html.erb

<%= form_with model: @post, local: true do |form| %>
...
<% end %>

routes.rb

  resources :communities do
    resources :posts
  end
RM64
  • 59
  • 1
  • 6
  • might same as this [form_with(model: @post, url: [@post, @community])](https://stackoverflow.com/questions/46919115/nested-resources-w-rails-5-1-form-with) – 步惊云 Apr 02 '19 at 10:56

1 Answers1

0

You can just use the url option, i.e:

form_for @post, local: true, url: posts_path do |form|

Use the path helper, you can find it's name by doing rake routes