ruby on rails - Building SQL3 db error -
i building database of skills , in origin thinking need title param them added required param. rid of title param can create new skills , description. right there error because looking :title. here 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 error when seek , submit new skill:
activerecord::statementinvalid in skillscontroller#create sqlite3::constraintexception: skills.title may not null: insert "skills" ("created_at") values (?)
i think easiest way bypass issue create skill.title not required not sure how prepare it. post /new form if helps:
<h1>add new skill</h1> <%= form_tag ({action: "create"}) %> <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 'title' line , made more problems. maintain messing code , researching , give thanks knows issue. cheers , 1 time again stackers!!!
looks created title
column not null
constraint, database won't allow record created without title.
if don't need it, should drop column database.
create migration:
bundle exec rails generate migration remove_title_from_skills
edit migration file created , add:
def alter remove_column :skills, :title end
run migration:
bundle exec rake db:migrate
remove other references :title
in application.
ruby-on-rails database sqlite3 sqlite3-ruby
No comments:
Post a Comment