小编use*_*831的帖子

在Ruby on Rails中添加布尔列值

我正在开发一个创建Web博客的Ruby on Rails项目.我希望在Post模型中添加一个名为features的布尔数据库字段.该字段应该可以通过我添加的活动管理界面进行编辑.

我使用了以下代码,但我甚至没有在网站上显示另一个列.

$rails generate migration addFeatured featured:boolean
$rake db:migrate
Run Code Online (Sandbox Code Playgroud)

我是Ruby on Rails的新手,非常感谢任何帮助.

我的index.html.erb文件(views)中的相关代码:

<th>Featured Post</th>
<td><%= post.featured %></td>
Run Code Online (Sandbox Code Playgroud)

Schema.rb:

ActiveRecord::Schema.define(:version => 20141126015126) do

create_table "active_admin_comments", :force => true do |t|
 t.string   "namespace"
 t.text     "body"
 t.string   "resource_id",   :null => false
 t.string   "resource_type", :null => false
 t.integer  "author_id"
 t.string   "author_type"
 t.datetime "created_at",    :null => false
 t.datetime "updated_at",    :null => false
end

add_index "active_admin_comments", ["author_type", "author_id"], :name =>    "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], :name => …
Run Code Online (Sandbox Code Playgroud)

ruby boolean ruby-on-rails activeadmin

6
推荐指数
2
解决办法
9488
查看次数

标签 统计

activeadmin ×1

boolean ×1

ruby ×1

ruby-on-rails ×1