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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:25:45+00:00 2026-06-01T15:25:45+00:00

I am using ruby key & value fields to save a jquery function to

  • 0

I am using ruby key & value fields to save a jquery function to the database and everything works fine but how can I separate the value params?

def update_background
  key = "#{current_user}.profile.background"
  settings = Settings.find_by_key(key) || Settings.new(key: key)
  settings.value = params[:bg_id], params[:color_id]

  respond_to do |format|
    format.json do
      if settings.save
        render text: "success"
      else
        render text: "failure"
      end
    end
  end
end

The above code works fine but the problem is my css is not formatted properly. The code usually shows like so

background:  url(../assets/stripes.png rgb(76, 72, 128))

In my helper file.

def saved_background
  key = "#{current_user}.profile.background"
  settings = Settings.find_by_key(key)
   if settings
     "url(#{settings.value})"
  end
end

How can I separate the 2 params in value so that my code will look like

background: rgb(76, 72, 128) url(../assets/stripes.png)
  • 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-01T15:25:47+00:00Added an answer on June 1, 2026 at 3:25 pm

    You’re basically saving an array to settings.value, and using it all within the url string.

    Either separate the settings into individual values, or use each element individually:

    "url(#{settings.value[0]}) #{settings.value[1]}"
    

    Edit Ah, it’s an AR field–so it’s likely being saved as just the string rep of the array. Trivial to check, and you should have already.

    You need to save it in the format you actually want it–so:

    settings.value = "url(#{params[:bg_id]}) #{params[:color_id]}"
    

    And:

    def saved_background
      key = "#{current_user}.profile.background"
      settings = Settings.find_by_key(key)
      settings.value if settings
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: Using Ruby it is simple to add custom methods to existing classes, but
I am trying to make a auto complete box using ruby on rails, jquery
I try to connect a server though SSH using Ruby, but I have an
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
Using Ruby (newb) and Regex, I'm trying to parse the street number from the
Using Ruby/RoR - The year is a string in the model/view. How do I
Using ruby regexp I get the following results: >> 'foobar'[/o+/] => oo >> 'foobar'[/o*/]
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I have been using Ruby for a while now and I find, for bigger

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.