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)
You’re basically saving an array to
settings.value, and using it all within theurlstring.Either separate the settings into individual values, or use each element individually:
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:
And: