Once a user create a record on my web app, he is redirected to the Home#show.
I would like to display the show view, but also add the partial of the create form view. How can I accomplish this?
What do I need to change to this form in order to force a "create" action on my show view?
<%= simple_form_for(@home, :html => { :class => "form-newsletter thirds" }) do |f| %>
<%= f.error_notification %>
<%= f.input :phone, placeholder: "Phone Number (5554440707)", label: false, input_html: { maxlength: 10, :style => 'height: 50px' }%>
<%= f.input :sender_name, placeholder: "Your Name", label: false, input_html: { maxlength: 60, :style => 'height: 50px' } %>
<div class="form-actions">
<%= f.submit "Place your Order", :type => :image, :src => image_path("checkout-logo-large.png") %>
</div>
<% end %>
The problem is happening because you are passing @home
to the form, which is already a saved record.
Change:
<%= simple_form_for(@home, ...
To:
<%= simple_form_for(Home.new, ...
This assumes that Home.new
is how you instantiate a new (unsaved) model. Alternatively, it may be simpler for you to just assign that to @home
in your controller, and leave the form as is:
@home = Home.new