【发布时间】:2015-03-31 10:08:14
【问题描述】:
在我的 Ruby on Rails 应用程序中,我试图让用户选择他们的颜色并将其作为网站背景。
在我的架构中,我有这个首选项表:
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
CSS 背景颜色在下面一行:
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;}
但我不确定如何根据数据库中的颜色更新颜色。
我已尝试点击此链接:http://blog.hasmanythrough.com/2007/10/18/simpler-than-dirt-restful-dynamic-css
但我得到了错误:undefined method formatted_colour_path for #<#<Class:0x6daa0a8>:0x6881b98>
在视图中:
在参数控制器中:
def show
@colour = Perference.find_by(user_id: session[:user_id]).colour
respond_to do |format|
format.html
format.css
end
end
有人可以帮忙吗?我知道我需要从数据库中检索颜色,然后使用它来更新 CSS,但我不知道该怎么做。
【问题讨论】:
-
是
formatted_user_path(@user为什么会出现formatted_colour_path这个错误,你能多贴一些代码 -
对不起,我应该添加进去,请查看更新后的问题
标签: css ruby-on-rails ruby database ruby-on-rails-3