ruby-1.9

str.each in Ruby isn't working

筅森魡賤 提交于 2019-11-30 11:02:23
I'm Learning Ruby. I found the method String#each at http://ruby-doc.org/core/classes/String.html . When I try using it... irb(main):001:0> "hello\nworld".each {|s| p s} NoMethodError: undefined method `each' for "hello\nworld":String ...but I get that NoMethodError . I'm using Ruby 1.9.1p253 so I don't think I'm using an old version. What's going on? scottd Ruby 1.9 no longer has each on the String class. Use either each_char or each_line depending on what you want to do. The docs for Ruby 1.9 String are http://ruby-doc.org/core-1.9.3/String.html . Use each_char instead: "hello\nworld".each

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

我怕爱的太早我们不能终老 提交于 2019-11-30 08:39:31
I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu . Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools installed. Running: $ brew doctor # Your system is raring to brew. I can upload and resize images in this configuration: rails 3.1.4 ruby 1.8.7 carrierwave 0.5.8 mini_magick 3.4 I can upload images in the new configuration: rails 3.2.3 ruby 1.9.3 (or 1.9.2) carrierwave 0.6.2 (followed by $ bundle update ) but resizing using mini_magick returns this

Understanding Ruby symbol as method call [duplicate]

China☆狼群 提交于 2019-11-30 07:18:42
This question already has an answer here: How to understand symbols in Ruby 11 answers class A def test "Test from instance" end class << self def test "Test from class" end end end p A.send(:test) # "Test from class" p A.new.method(:test).call # "Test from instance" Here symbol works as expected, but here: s="test" s1=:s p s1 # :s why :s is printed here?? I dont understand the reason behind it. Can anyone please explain for me ? Symbols are sort of lightweight strings (though they are not strings). The send() and method() methods can take strings or symbols; one is converted to the other in

Undefined method 'on' for ActionModel

北慕城南 提交于 2019-11-30 03:17:49
问题 I'm getting the following error: NoMethodError in Users#new Showing .../app/views/users/form/_new.haml where line #7 raised: undefined method `on' for #<ActiveModel::Errors:0x007fb599ec6610> The code in line 7 is: 7: = errors_for user, :first_name And the application_helper.rb: def errors_for(model, field) error = case errors = model.errors.on(field) ... end 'on' is a default method in ActiveRecord. Why doesn't this work? 回答1: If you're using Rails 3, then the problem is that there's no "on"

Where are methods defined at the ruby top level?

故事扮演 提交于 2019-11-30 02:27:39
At the top level, method definition should result in private methods on Object , and tests seem to bear this out: def hello; "hello world"; end Object.private_instance_methods.include?(:hello) #=> true Object.new.send(:hello) #=> "hello world" However, the following also works at top level ( self.meta is the eigenclass of main ): self.meta.private_instance_methods(false).include?(:hello) #=> true It appears that the hello method is simultaneously defined on the eigenclass of main as well as on Object . What's going on? Note that the false parameter to private_instance_methods excludes super

How can I choose Ruby version on Heroku?

独自空忆成欢 提交于 2019-11-30 01:47:47
I use Ruby 1.9.x syntax in my Rails 3 app, but after pushing it to Heroku it crashes due to older Ruby version (1.8). How can I control it? Heroku's current stack, Cedar, uses 1.9.2 by default. Cedar also supports specifying the Ruby version in your Gemfile . Currently, 1.9.2 and 1.9.3 are valid options . # Gemfile source "https://rubygems.org" ruby "1.9.3" ... More details are available in the Ruby support article: https://devcenter.heroku.com/articles/ruby-support If you are currently using Aspen or Bamboo, you can switch to 1.9.2 by using the stack:migrate command: $ heroku stack:migrate

Ruby - UTF-8 file encoding

淺唱寂寞╮ 提交于 2019-11-29 21:21:00
We all know the "magical" # encoding: utf-8 line. But I've seen several other alternative notations, some of them pretty wild. Do you know or use any of those? Is there some more general rule of what is acceptable? Edit: Ok, apparently there are exactly 3 ways: # encoding: UTF-8 # coding: UTF-8 # -*- coding: UTF-8 -*- (more at http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings ) No, there are not "exactly 3 ways" to specify the 'magic comment' -- there are an infinite number of them. Any comment on the first line that contains coding: will work, according to JEG2 : ...

str.each in Ruby isn't working

你说的曾经没有我的故事 提交于 2019-11-29 16:28:34
问题 I'm Learning Ruby. I found the method String#each at http://ruby-doc.org/core/classes/String.html. When I try using it... irb(main):001:0> "hello\nworld".each {|s| p s} NoMethodError: undefined method `each' for "hello\nworld":String ...but I get that NoMethodError . I'm using Ruby 1.9.1p253 so I don't think I'm using an old version. What's going on? 回答1: Ruby 1.9 no longer has each on the String class. Use either each_char or each_line depending on what you want to do. The docs for Ruby 1.9

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

笑着哭i 提交于 2019-11-29 12:19:11
问题 I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu . Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools installed. Running: $ brew doctor # Your system is raring to brew. I can upload and resize images in this configuration: rails 3.1.4 ruby 1.8.7 carrierwave 0.5.8 mini_magick 3.4 I can upload images in the new configuration: rails 3.2.3 ruby 1.9.3 (or 1

Why are all strings ASCII-8BIT after I upgraded to Rails 3?

筅森魡賤 提交于 2019-11-29 02:21:37
I upgraded to RoR 3.0.1 and Ruby to 1.9.2. Now all the strings in my views are ASCII-8BIT? I believe I have my app set up to use UTF 8 application.rb config.encoding = "utf-8" database.yml development: adapter: mysql encoding: utf8 I'm running OS X RVM rvm 1.0.16 Ruby ruby-1.9.2-p0 Rails 3.0.1 I'd expect that the enoding would be UTF 8 not ASCII business.desc.encoding # ASCII-8BIT Since 1.9.x can concatenate strings of different encodings we see a lot of errors like this. <p class="description"><%= truncate(business.desc, :length => 17) %></p> The Error incompatible character encodings: ASCII