Getting a missing params information in the controller., here is the code of the controller
class SubjectsController < ApplicationController
layout false
def new
@subject=Subject.new
end
def create
@subject = Subject.create(subject_params)
if @subject.save
redirect_to(:action => 'index')
else
render('new')
end
end
private
def subject_params
params.require(:subject).permit(:name, :position, :visible)
end
end
and here is the code for new.html.erb
<%= link_to("<< Back to List", {:action => 'index'}, :class => 'back-link') %>
<div class="subjects new">
<h2>Create Subject</h2>
<%= form_for(:subject, :url => {:action => 'create'}) do |f| %>
<table summary="Subject form fields">
<tr>
<th>Name</th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th>Position</th>
<td><%= f.text_field(:position) %></td>
</tr>
<tr>
<th>Visible</th>
<td><%= f.text_field(:visible) %></td>
</tr>
</table>
<div class="form-buttons">
<%= submit_tag("Create Subject") %>
</div>
<% end %>
</div>
Hoping someone will be able to tell why do I get this error:
ActionController::ParameterMissing in SubjectsController#create
param is missing or the value is empty: subject
Extracted source (around line #34):
def subject_params
params.require(:subject).permit(:name, :position, :visible)
end
end
Thanks