Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:31+00:00 2026-05-22T03:16:31+00:00

I’m sure there has to be a very simple solution to my problem but

  • 0

I’m sure there has to be a very simple solution to my problem but i don’t know why i cant seem to put my finger on it, the problem is that I’m trying to submit a form but every time i submit the form the create action controller gives the following error

Mysql2::Error: Column ‘preffered_players’ cannot be null: INSERT INTO saved_sessions (preffered_players, session_id, preffered_opponents, game_id, game_type, opponents_list, banned_players, players_list) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

how ever all these values that the error says are null are passed through parameters as soon as the form is submitted, can anyone tell me how to use the parameter values that i get from the form to fill in the little nulls in my query, create controller is as follow

def create
    opponents_list = params[:opponents_list]
    banned_players = params[:banned_players]
    game_type = params[:game_type]
    session_id = params[:session_id]
    preffered_opponents = params[:preffered_opponents]
    game_id = params[:game_id]
    players_list = params[:players_list]
    preffered_players = params[:preffered_players]

    @saved_sessions = SavedSession.new(params[:saved_sessions])

    respond_to do |format|
      if @saved_sessions.save
        format.html { redirect_to(@game, :notice => 'Game was successfully created.') }
        format.xml  { render :xml => @game, :status => :created, :location => @game }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @game.errors, :status => :unprocessable_entity }
      end
    end
  end 

thanks for any advice…

i’m including the form code however its very messy(its a huge form) plus its in haml 🙂

- form_tag('/saved_sessions',:method => :post, :id => "new_game") do
.select_option
  .list_col1
    .fl
      %img{:alt => "image", :border => "0", :src => "/images/happy_face.png"}/
    .blue_col
      = text_field_tag :preffered_opponents, "", :class => :blue_bar
    .clr
  .list_col2
    .list_col2_top_row
      .radio_row
        .fl
          %input{:type => "radio", :name => "battle_scale", :value => "3"}
        .fl 3 vs 3
        .fl
          %input{:type => "radio", :name => "battle_scale", :value => "5"}
        .fl 5 vs 5
        .clr
      %div
        .fl
          %img{:alt => "image", :border => "0", :src => "/images/sad_face.png"}/
        .fl
          /%input#banned_players.white_bar{:type => "text"}/
          = text_field_tag :banned_players, "", :class => :white_bar
        .clr
    .versus_row
      #inputs-vs.versus_col1
        .versus_col_row
          .blue_col
            /%input#input-1-vs.blue_bar{:type => "text"}/
            = text_field_tag 'input-1-vs', "", :class => :blue_bar
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .clr
        .versus_col_row
          .blue_col
            /%input#input-2-vs.blue_bar{:type => "text"}/
            = text_field_tag 'input-2-vs', "", :class => :blue_bar
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .clr
        .versus_col_row
          .blue_col
            /%input#input-3-vs.blue_bar{:type => "text"}/
            = text_field_tag 'input-3-vs', "", :class => :blue_bar
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .clr
        .versus_col_row
          .blue_col
            /%input#input-4-vs.blue_bar{:type => "text"}/
            = text_field_tag 'input-4-vs', "", :class => :blue_bar
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .clr
        .versus_col_row
          .blue_col
            /%input#input-5-vs.blue_bar{:type => "text"}/
            = text_field_tag 'input-5-vs', "", :class => :blue_bar
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .clr
      .versus_col2
        %img{:alt => "0", :border => "0", :src => "/images/vs.png"}/
      #inputs.versus_col1
        .versus_col_row
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .blue_col
            /%input#input-1.pink_bar{:name => "blah", :type => "text"}/
            = text_field_tag 'input-1', "", :class => :pink_bar
          .clr
        .versus_col_row
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .blue_col
            /%input#input-2.pink_bar{:name => "blah", :type => "text"}/
            = text_field_tag 'input-2', "", :class => :pink_bar
          .clr
        .versus_col_row
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .blue_col
            /%input#input-3.pink_bar{:name => "blah", :type => "text"}/
            = text_field_tag 'input-3', "", :class => :pink_bar
          .clr
        .versus_col_row
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .blue_col
            /%input#input-4.pink_bar{:name => "blah", :type => "text"}/
            = text_field_tag 'input-4', "", :class => :pink_bar
          .clr
        .versus_col_row
          .fl
            %img{:alt => "image", :border => "0", :src => "/images/lock.png"}/
          .blue_col
            /%input#input-5.pink_bar{:name => "blah", :type => "text"}/
            = text_field_tag 'input-5', "", :class => :pink_bar
          .clr
      .clr
    .session_row
      %p
        %b You can save and share this session by entering your email. A unique code will be sent
      %p.small_text (Session are stored for 30 days)
    .seesion_send_row
      .fl
        /%input.big_white_bar{:type => "text"}/
        = text_field_tag 'email_bar', "", :class => :big_white_bar
      .fl
        %span 2+2=
        %span
        %span
          /%input.small_bar{:type => "text"}/
          = text_field_tag 'code_bar', "", :class => :small_bar
      .fl
        /%a{:href => "#."}
        /%img{:alt => "image", :border => "0", :src => "/images/send_button.png"}/
        = submit_tag("Send")

hope this can help you guys better understand the problem..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:16:32+00:00Added an answer on May 22, 2026 at 3:16 am

    You seem to be pulling from 2 different places. The block of code at the top of the method is pulling the values from the top level of the incoming params, but then later you initialize a new SavedSession using the params[:saved_sessions] input. The two things don’t seem to match…

    if saved_sessions.opponents_list is found at opponents_list = params[:opponents_list] in the first line, then when you later try to save params[:saved_sessions], you’re getting it from a different spot in the params…

    EDIT: so you do not need both of the sets of values you have in the action. if you build your form like this (or at least something like this) you’ll get the params correctly and can just blindly send them into SavedSession.new, and then call .save.

    - form_for(@aved_session) do |f| 
      -.blue_col
          = f.text_field :preffered_opponents, "", :class => :blue_bar
    

    If you allow f.text_field to build the id and name then rails magic will make sure that they are named/id’d correctly and then more rails magic interprets them and builds your input parameters correctly. This will build your params as:

    params = {:saved_session => {:preferred_opponents => "text value" }...
    

    Then you can pull those params out:

    saved_session_input = params[:saved_session]
    

    and pass them into new just like you are. the difference is that now those parameters are actually IN there.

    The way you have it is like this:

    params = {:preferred_opponents => "text value", :saved_session => {:preferred_opponents => nil }...
    

    this means you’re passing nil in for the expected values for new. Note that you don’t actually assign your local values to the new saved_session before calling save.

    I hope this is clearer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.