Reputation: 1181
I have a namespaced resource in my Rails 5 app and want the correct form for it.
My scaffold for Platform in Rails 5 gave me:
<%= form_with(model: platform, local: true ) do |form| %>
In Rails 4 I would include my namespace ('customer') like:
<%= form_for [:customer, @platform] do |f| %>
So what is the equivalent in Rails 5?
Upvotes: 8
Views: 5781
Reputation: 1712
In your form you would do something like this.
<%= form_for [@customer, @platform] do |form| %>
...
<% end %>
In new.html.erb
or equivilent new
method:
<%= render 'form', customer: @customer %>
In your new controller method (depending on your relationships)
def new
@customer = @platform.customers.build
end
Using form_with
<%= form_with(model: [:customer, @platform]) do |form| %>
...
<% end %>
http://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html#method-i-form_with
Upvotes: 16