I have a model called Person
, and I want to have a resource called Employee
. I found that this will stop the form_for
magic.
I need to pass in the @person
object itself so form_for can choose the correct action path (create or update).
However this will mean that form_for uses POST people_path
and PUT person_path
in the output, instead of employee_path
s.
Is it possible to have all the Rails convention goodies while my model and controller have different names?
If you want to use "employees" in routes/url you can use "path" in routes eg. create controller as people_controller but in routes
resources :people, path: "employees"
so routes will be like
new_person GET /employees/new
people GET /employees
etc
So following will work
<%= form_for @people do |f| %>
...
<% end %>
Note: For this You have to use Person model
you can add a option: url: employee_path
e.g.
<%= form_for @people, :as => :post, :url => employee_path(@people) do |f| %>
...
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With