小编ToT*_*lan的帖子

NoMethodError:未定义的方法`匹配?' 对于"Ruby":String

我正在尝试检查来自用户的输入是否与RegEx匹配,[a-zA-z]因此我检查了文档以获取正确的方法.我match?Ruby-doc.org中找到并将docs中显示的示例复制到irb,但是true我没有得到这个:

2.3.3 :001 > "Ruby".match?(/R.../) 
NoMethodError: undefined method `match?' for "Ruby":String
Did you mean?  match
        from (irb):1
        from /usr/local/rvm/rubies/ruby-2.3.3/bin/irb:11:in `<main>'
Run Code Online (Sandbox Code Playgroud)

为什么这种方法在我的irb中不起作用?

ruby regex match code-documentation nomethoderror

7
推荐指数
1
解决办法
6607
查看次数

在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
查看次数