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

  • Home
  • SEARCH
  • 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 943271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:24:37+00:00 2026-05-15T22:24:37+00:00

In a Ruby on Rails application I am trying to use information from fields

  • 0

In a Ruby on Rails application I am trying to use information from fields that are not associated with the model in validation.

Here is part of the model as an example (the whole model has gotten kinda big):

class Scorecard < ActiveRecord::Base
  belongs_to :course
  belongs_to :user

  validate :attributes_consistency

  def attributes_consistency
    # Executed for all scorecards.  Checks if the user completed the hole attributes correctly
    if ( params[:no_fairways] and any_fairways? and !only_nine? ) or ( params[:no_fairways] and !any_h1_to_h9_score_blank and any_h1_to_h9_fairway? and only_nine? ) or ( params[:no_fairways] and !any_h10_to_h18_score_blank and any_h10_to_h18_fairway? and only_nine? )
      errors.add_to_base("You inidicated that you missed all the fairways, but you also marked one or more fairways in the scorecard.  Either uncheck the fairways mistakenly marked or uncheck the 'No fairways' checkbox.")
    end
    if ( params[:no_girs] and any_girs? and !only_nine? ) or ( params[:no_girs] and !any_h1_to_h9_score_blank and any_h1_to_h9_gir? and only_nine? ) or ( params[:no_girs] and !any_h10_to_h18_score_blank and any_h10_to_h18_gir? and only_nine? )
      errors.add_to_base("You inidicated that you missed all the greens, but you also marked one or more greens in the scorecard.  Either uncheck the marked greens on the scorecard or uncheck the 'No GIRs' checkbox.")
    end
  end # attributes_consistency


  def any_h1_to_h9_score_blank?
    h1_score.blank? or h2_score.blank? or h3_score.blank? or h4_score.blank? or h5_score.blank? or h6_score.blank? or h7_score.blank? or h8_score.blank? or h9_score.blank?
  end
  def any_h10_to_h18_score_blank?
    h10_score.blank? or h11_score.blank? or h12_score.blank? or h13_score.blank? or h14_score.blank? or h15_score.blank? or h16_score.blank? or h17_score.blank? or h18_score.blank?
  end

  def any_h1_to_h9_fairway?
    h1_fairway? or h2_fairway? or h3_fairway? or h4_fairway? or h5_fairway? or h6_fairway? or h7_fairway? or h8_fairway? or h9_fairway?
  end
  def any_h10_to_h18_fairway?
    h10_fairway? or h11_fairway? or h12_fairway? or h13_fairway? or h14_fairway? or h15_fairway? or h16_fairway? or h17_fairway? or h18_fairway?
  end

  def any_h1_to_h9_gir?
    h1_gir? or h2_gir? or h3_gir? or h4_gir? or h5_gir? or h6_gir? or h7_gir? or h8_gir? or h9_gir?
  end
  def any_h10_to_h18_gir?
    h10_gir? or h11_gir? or h12_gir? or h13_gir? or h14_gir? or h15_gir? or h16_gir? or h17_gir? or h18_gir?
  end

So how can I access params from the model?

  • 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-15T22:24:37+00:00Added an answer on May 15, 2026 at 10:24 pm

    Don’t let params sneak up to the model. There’s no point of having a controller in that case. Instead, checkout this episode from Railscasts that talks about virtual attributes that do not go into the database but can still be used for validations.

    You don’t need a corresponding model attribute for the virtual attributes. Define attributes local to the class such as @no_fairways that hold the state.

    class ScoreCard < ActiveRecord::Base
      # define attributes and accessors for both fields
      attr_accessor :no_fairways, :no_girs
    
      ..
    end
    

    Now inside you form, you could just write:

    <% form_for @scorecard %>
      <%= f.check_box :no_fairways %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to use mysql as a database for my rails application. here
I am trying to implement a rails Recipe application from the site http://oreilly.com/ruby/archive/rails-revisited.html .
I'm trying to use geoip's web service for a ruby on rails application. They
In my Ruby on Rails application, I am trying to protect part of the
I'm trying to send emails from my Ruby on Rails application, and whenever I
I am trying to deploy my Ruby on Rails application on Media Temple. The
When trying to run a new refinerycms application with ruby 1.9.2 rails 3.2.1 and
I have a Ruby on Rails application that needs to find a home in
I'm developing a Ruby on Rails application that needs to allow the user to
says if i develop a Ruby on Rails application using Rails 2.3.2, will that

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.