I'm really new to RoR, and I'm trying to create a nested form using simple_form but I keep seeing this error turn up:
NoMethodError in Forms#show
undefined method `model_name' for nil:NilClass
I've taken a look at these links, but to no avail. I've also considered whether I have any typos, or have made a mistake about use of the singular/plural.
- Creating multiple nested forms using simple_form and rails 4
- How should I use rails and simple_form for nested resources?
- Rails - Using form_for and fields_for, how do you access the sub-object while in the fields_for block?
- Ruby on Rails: undefined method `model_name' for NilClass:Class
Here's my _form.html.erb
code, the error seems to be coming from the first line:
<%= simple_form_for([@form, @customformd]) do |f| %>
<%= f.input :legislation, label: 'Which Act?' %>
<%= f.input :provision, label: 'Which provision?', collection: [ "Act A", "Act B", "Act C" ] %>
<%= f.input :RB, label: 'Referring Body', collection: [ "A", "B", "C", "D", "E", "F"] %>
<%= f.button :submit %>
<% end %>
Here's my customformd.rb
code:
class customformd < ApplicationRecord
belongs_to :form
end
Here's my customformds_controller
code:
class CustomformdsController < ApplicationController
def create
@form = Form.find(params[:form_id])
@cformftcd = @form.customformds.create(customformds_params)
redirect_to form_path(@form)
end
private
def customformd_params
params.require(:customformd).permit(:RB, :legislation, :provision)
end
end
Here's a snippet of the offending part of the show.html.erb
code:
<%= render @form.customformd %>
<h5>Add Custom Form D Specific Info:</h5>
<%= render 'customformds/form' %>
Thank you very much in advance!