I am building a database of skills and in the beginning thinking that I would need a title param for them I added it as a required param. I would like to get rid of the title param all together so that I can just create new skills and a description. Right now there is an error because it is also looking for a :title. Here is my controller:
class SkillsController < ApplicationController
def index
@skills = Skill.all
end
def show
@skills = Skill.all
end
def new
@skills = Skill.all
end
def create
@skills = Skill.new(skill_params)
if @skills.save
redirect_to :action => 'index'
else
@skills = Skill.find(:all)
render :action => 'new'
end
end
def edit
@skills = Skill.find(params[:id])
@skills = Skill.find(:all)
end
def update
@skills = Skill.find(params[:id])
if @skills.update_attributes(params[:skill])
redirect_to :action => 'show', :id => @skills
else
@skills = Skill.find(:all)
render :action => 'edit'
end
end
def delete
Skill.find(params[:id]).destroy
redirect_to :action => 'index'
end
def show_skills
@skills = Skill.find(params[:id])
end
end
private
def skill_params
params.require(:skill).permit(:attribute_1, :attribute_2, :attribute_3)
end
and here is my error when I try and submit a new skill:
ActiveRecord::StatementInvalid in SkillsController#create
SQLite3::ConstraintException: skills.title may not be NULL: INSERT INTO "skills" ("created_at") VALUES (?)
I think the easiest way to bypass this issue is to make skill.title not required but I am not sure for certain how exactly to fix it. I will also post my /new form if that helps:
<h1>Add new Skill</h1>
<%= form_tag ({action: "create"}) do %>
<p><label for="skill">Skill</label>:
<%= text_field 'skill', 'title' %></p>
<p><label for="skill_description">Description</label><br/>
<%= text_area 'skill', 'description' %></p>
<%= submit_tag "Create" %>
<% end %>
<%= link_to 'Back', {:action => 'index'} %>
I tried getting rid of the 'title' line and it made even more problems. I will keep messing with the code and researching and thank you anyone who knows anything about my issue. Cheers and thanks again stackers!!!