Rails 控制台似乎将其字符输出限制为大约 880 个字符。我如何消除这个限制?
打印大型对象或数据库中的文本字段会给出如下输出:
=> #<User id: ....
system_password: ni
Run Code Online (Sandbox Code Playgroud)
(...为了简洁而插入。输出包含大量文本。)
您可以看到输出被截断/限制/限制,因此“ni”之后不会显示任何内容(应该至少是“l”,表示“nil”)。
这太烦人了。它不允许我完全检查数据库中包含大量文本的字符串/文本字段。
我认为它一定是某个地方的设置,但我似乎找不到它。
如何消除此限制,以便我可以看到所有文本输出?
可能重复:
消除Rails 2.3样式的插件和弃用警告
当我这样做时,我收到以下错误heroku run console:
$ heroku run console
Running `console` attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out an d bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
DEPRECATION WARNING: You have Rails 2.3-style …Run Code Online (Sandbox Code Playgroud) ruby-on-rails heroku rails-console ruby-on-rails-3 ruby-on-rails-3.2
我正在 Rails 控制台中寻找一种方法来查找以特定字符串结尾的任何值,并从值中删除该字符串。
大致如下:
Model.all.each{|x| x.duration.slice!(" weeks")}.where("duration IS NOT NULL")
Run Code Online (Sandbox Code Playgroud)
因此,诸如“47 周”之类的值只是变成“47”,但没有 Slice 方法ActiveRecord/ActiveModel,而且我不知道等效的方法。
有任何想法吗??
提前致谢...
我有一个名为 Dish 的模型,它的属性成本为 float 类型。我已将精度设置为 15,小数位数设置为 2。问题出在 Rails 控制台中,成本值以科学计数法显示。
cost: 0.102e2
如何以小数形式显示?
我在模型的yml夹具中添加了一个条目.然后rails console test.但新记录不在数据库中.
如何"更新"测试数据库以在rails控制台中访问它?
在Rails 3.0.7中工作,使用内置单元测试.
谢谢.
任何机构都能告诉我用什么命令来清除rails控制台中的所有变量?
例如
1.9.1 :001 > permissions = {:show => true}
=> {:show=>true}
1.9.1 :001 > foo = "bar"
=> "bar"
Run Code Online (Sandbox Code Playgroud)
我需要一个命令,可以将所有变量重置为nil而无需重启rails console本身.
任何建议将非常感谢.
我需要在User模型中选择第二个条目.
User.second没有工作,也没有User.2或User.two.
我正在尝试设置u第二个用户条目(u = User.2)
我正在玩Rails控制台.偶然的机会,我意外地将一个对象转换为一个字符串.以下是我的代码.
user = User.find(1)
user.to_s # returns <User:0x00000103ada530>
Run Code Online (Sandbox Code Playgroud)
我的问题是,什么是<User:0x00000103ada530>?它是否像用户的ID?<User:0x00000103ada530>我会回来吗?User.find(1)
谢谢
谷歌现在严重失败了.我需要做的就是从Heroku rails控制台更新一个属性,将用户设置为admin.
我找不到一个简单的答案.我一直在尝试的是:
Record.update_attribute(:roles_mask, "1")
记录是正确的记录.
'undefined method'更新属性''
我不能只打字Record.roles_mask = 1?
编辑.
我使用了Record,在示例中我不应该这样做.我所做的就是这样:
ian = User.where(:id => '5')
ian.update_attribute(:roles_mask, '1')
Error: undefined method 'update_attributes'
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的rails控制台在我的控制器中调用公共post方法.
rails c
app.post '/servers/important_method'
Run Code Online (Sandbox Code Playgroud)
这显然给了我:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
Run Code Online (Sandbox Code Playgroud)
有没有办法创建会话并调用该方法?
编辑:我可以创建一个视图并重新启动生产环境,但我想避免这种情况.
rails-console ×10
ruby-on-rails ×10
heroku ×2
activemodel ×1
activerecord ×1
irb ×1
testing ×1