mardi 31 mars 2015

Ruby on Rails change background colour in CSS according to database

In my Ruby on Rails application I am trying to allow the user to choose their colour and have this as the sites background.


In my schema I have this preferences table:



create_table "perferences", force: :cascade do |t|
t.integer "user_id"
t.integer "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "colour"
end


The CSS background colour is in the following line:



body{line-height:1;height:100%;width:100%;color:#B2BFCB;background:#002952;text-align:center;font-family:"Apercu Regular", Calibri, sans-serif;font-weight:normal;font-style:normal;margin:0;padding:0;}


But I am unsure as to how to update the colour based upon the colour in the database.


I have tried to follow this link: http://ift.tt/19vMCMZ But I got the error: undefined method formatted_colour_path for #<#<Class:0x6daa0a8>:0x6881b98>


In the view:


In the perferences controller:



def show
@colour = Perference.find_by(user_id: session[:user_id]).colour
respond_to do |format|
format.html
format.css
end
end


Can someone please help. I understand that I need to retrieve the colour from the database and then use this to update the CSS, but I am not sure how to do this.


Aucun commentaire:

Enregistrer un commentaire