Whenever I use simple_form_for(), it defaults to "my_subclasses_path" rather than "my_base_classes_path". How can I tell it to not use the subclass?
In my case, I have a User object, but also many subclasses. I want to use the standard user urls as all the subclasses work the same for these forms.
In addition, I want to stop simple_form from naming the properties after the subclass. For example, if the subclass is "Admin", I want the submitted parameters to be "params[:user]" and not "params[:admin]".
I find the above to be REALLY odd because the form actually says "user[first_name]" and NOT "admin[first_name]" - but simple_form seems to want to make it params[:admin] anyway.开发者_JAVA技巧
Basically, subclasses are causing simple_for to not behave properly. I wish there was an option like
base_class => 'User'
That would handle all of these things.
If you pass in the :url option as rafaelfranca suggests, along with the :as option, it should work correctly. For example:
simple_form_for(@admin, :url => user_path(@admin), :as => :user)
This gives me the correct form action and parameters (e.g. user[name] instead of admin[name]).
Pass the :url
option to simple_form_for
.
eg.: simple_form_for(@admin, :url => users_path)
精彩评论