There are resources :products . The form looks like this:

 <%= form_for(product) do |f| %> <% if product.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:</h2> <ul> <% product.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :title %> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :description %> <%= f.text_area :description, rows: 6 %> </div> <div class="field"> <%= f.label :image_url %> <%= f.text_field :image_url %> </div> <div class="field"> <%= f.label :price %> <%= f.text_field :price %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> 

    1 answer 1

    You need to pass an additional url parameter in the form_for form_for(product) in which to form the c json path. In the simplest case, you can just score a line with your hands.

     <%= form_for(product, url: '/products.json') do |f| %> 

    However, they usually do not do this, but form a path with the help of helpers, so that in case of a change in routes.rb, you do not have to edit the path somewhere else in the project code

     <%= form_for(product, url: products_path(format: :json)) do |f| %>