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 4569680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:15:15+00:00 2026-05-21T19:15:15+00:00

I want to validate a form that gets submitted. The name of the param

  • 0

I want to validate a form that gets submitted. The name of the param that is send is ratings. And that param gets saved in the rating_score column.

I want to validate that the param ratings is only between 1 and 5.

I have put this in my model:
validates_inclusion_of :rating_score, :in => 1..5

After that I submitted my form with the param ratings = 6 and it got saved in my database.

My controller:

  def rate
    @konkurrancer = Konkurrancer.find(params[:id])
    @konkurrancer.rating_score ||= 0
    @container = "Konkurrancer"+@konkurrancer.id.to_s
    @konkurrancer.rating_score += params[:vind][:ratings].to_i
    @konkurrancer.ratings += 1
    @konkurrancer.save

    respond_to do |format|
      format.js
    end
  end

My model:

class Konkurrancer < ActiveRecord::Base
attr_accessible :rating_score
validates_inclusion_of :rating_score, :in => 1..5
end

My log when submitting my form:

Started POST "/konkurrancers/rate/7" for 127.0.0.1 at 2011-05-03 23:23:53 +0200
  Processing by KonkurrancersController#rate as */*
  Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"h6RSZbuVVfYIvdNb31xS6Oo7Q8o
1JxvVL24aoJ2GQ/o=", "vind"=>{"ratings"=>"6"}, "id"=>"7"}

Completed 200 OK in 488ms (Views: 239.0ms | ActiveRecord: 20.0ms)

How to do the validation?

  • 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-21T19:15:16+00:00Added an answer on May 21, 2026 at 7:15 pm

    Try to save it before render view. Looks like your object is not saved, but your rating_score is dirty and equal 6.

      def rate
        @konkurrancer = Konkurrancer.find(params[:id])
        @konkurrancer.rating_score ||= 0
        @container = "Konkurrancer"+@konkurrancer.id.to_s
        @konkurrancer.rating_score += params[:vind][:ratings].to_i
        @konkurrancer.ratings += 1
        if @konkurrancer.save
          respond_to do |format|
            format.js
          end
        end
      end
    

    OLD

    Ok you are validating rating_score but not raitings

    So if you set ratings = 6 it will saved.

    But if you will set rating_score = 6 it won’t be saved, because your validation is right.

    Try this

    class Konkurrancer < ActiveRecord::Base
      attr_accessible :rating_score
      validates_inclusion_of :rating_score, :in => 1..5
    end
    

    or

    class Konkurrancer < ActiveRecord::Base
      attr_accessible :rating_score
      validates :rating_score, :inclusion => { :in => 1..5 }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate a registration form that accepts an email address in the
I want to validate a form fields (text) input. It should only be a
Hi I want to validate a form input so it only takes the numbers
I have a form that I want to validate before the user is able
I have a simple form that I want to validate using blur if the
I want to validate my form on button click. For that I used (#trade).validate();
I want to use class annotations to validate a razor form that collects data
I have a form that I want to validate looks like this: <!DOCTYPE html
I have a form that i want to validate ( show validation summary, show
I want to submit a form. But before that I wanna validate it. The

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.