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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:40:36+00:00 2026-06-14T06:40:36+00:00

I have a Settings table with 5 boolean fields. I want to be able

  • 0

I have a Settings table with 5 boolean fields. I want to be able to create and update those fields via JSON. From what I understand, Rails converts all parameters to strings, so that boolean values always return true. If I send:

{ "settings": { "setting1":true, "setting2":false } }

And then try doing: Setting.new(params[:settings]), both settings will be true in the database, since the second setting’s value of false is translated to "false", and thus actually evaluates to true. Actually I can’t even do that, as I get:

NoMethodError (undefined method `stringify_keys' for #<String:0x000000213dcbd0>)

on that line. Some suggestions from the internet say to compare the parameters against "true", and then store that. This is a huge pain though, because then I can’t take advantage of mass-assignment. I don’t want to have to do this:

@setting = Setting.new
@setting.setting1 = (params[:settings][:setting1].eql? "true")
...

For all 5 fields, especially since I will have to do that for create, update, and even from other controllers (some controllers accept JSON to create a settings object along with their own attributes).

Is there a better way to go about this? JSON APIs seem pretty standard with Rails, it seems like this would be taken care of in a more elegant way?

  • 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-06-14T06:40:37+00:00Added an answer on June 14, 2026 at 6:40 am

    How about just making a convertor class and sticking it in a before filter?

    class ApplicationController < ActionController::Base
      before_filter BooleanFilter
    end
    
    class BooleanFilter
      def self.filter(controller)
        # change all relevant string params to booleans, raise an exception if something other than "true" or "false" is detected
        # eg. params[:setting][:setting1] = ( params[:setting][:setting1] == "true" ? true : false )
      end
    end
    

    It is probably more consistent with Rails to assign the changed params to a new Hash object and to pass that to the model.

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

Sidebar

Related Questions

I have a question regarding the table structure of my settings table. I've taken
I have a table with sets of settings for users, it has the following
I have a data Table with numbers formatted according to the current regional settings.
I have kind of a settings table where are columns like type, value, company,
I access a a postgres table using SQLAlchemy. I want a query to have
I have an app running. I want to create a UserNotifications migration that belongs_to
I have a settings table in a database that is accessed through Entity Framework
I'm trying to find the best way to retrieve fields from a table, depending
I have a table in the database for various settings in my application. These
I have a listview that serves as a user-settings table. Each key is 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.