My view for the new form is
<h1>Add Form 3C </h1>
<%= form_for([@basiccase, @form3c]) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :date_of_investigation %>
<%= f.date_select :date_of_investigation, {:include_blank => true, :default => nil} %>
</div>
<div class="actions">
<%= f.submit "Add Form" %>
</div>
<% end %>
My controller for new and create are
def new
@title = "New Form 3C"
@basiccase = Basiccase.find_by_id(params[:basiccase_id])
@form3c = @basiccase.build_form3_c
end
def create
@basiccase = Basiccase.find_by_id(params[:basiccase_id])
@form3c = @basiccase.build_form3_c(params[:form3c])
if @form3c.save
flash[:success] = "Form created!"
redirect_to current_user
else
flash[:warning] ="Failed to create a Form"
render 'users/show'
end
end
I’m unable to get the value of params[:form3c] into the the create controller. when I tried to check puts params[:form3c] it is showing blank. Can Any on help me where i’m wrong
A params key will be based on your class name. Rails expects class names to be mixed case (e.g. BasicCase) and creates the param key by lowercasing and separating the words with an underscore.
You can check this in a Rails console using #underscore:
I imagine you have named your class Form3C which becomes form3_c as Dylan suggested.
You may want to consider renaming both your models to BasicCase and Form3c which should give you params basic_case_id and form3c.