Keep Getting "Could not find passenger (>=0) amongst" While Passenger - ruby
I've been debugging this more than one day, and no luck,
After I install ruby, gems, and Passenger, I tried to start Passenger, but I keep getting "Could not find passenger":
passenger#dragon:/usr/website/myapp/current$ passenger start -p 4000 -e production -d
/home/passenger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find passenger (>= 0) amongst [actionmailer-3.2.8, actionmailer-3.2.3, actionpack-3.2.8, actionpack-3.2.3, activemodel-3.2.8, activemodel-3.2.3, activerecord-3.2.8, activerecord-3.2.3, activeresource-3.2.8, activeresource-3.2.3, activesupport-3.2.8, activesupport-3.2.3, arel-3.0.2, bcrypt-ruby-3.0.1, builder-3.0.3, builder-3.0.0, cape-1.4.0, capistrano-2.13.4, coffee-rails-3.2.2, coffee-script-2.2.0, coffee-script-source-1.3.3, devise-2.1.2, devise_ldap_authenticatable-0.6.1, erubis-2.7.0, execjs-1.4.0, guess_html_encoding-0.0.4, high_voltage-1.1.1, highline-1.6.15, hike-1.2.1, i18n-0.6.1, i18n-0.6.0, journey-1.0.4, jquery-rails-2.0.2, jruby-pageant-1.1.1, jsmin-1.0.1, json-1.7.3, libv8-3.3.10.4-x86-linux, mail-2.4.4, mime-types-1.19, mini_magick-3.4, multi_json-1.3.6, net-ldap-0.2.2, net-scp-1.0.4, net-sftp-2.0.5, net-ssh-2.6.0, net-ssh-gateway-1.1.0, nokogiri-1.5.5, orm_adapter-0.4.0, polyglot-0.3.3, rack-1.4.1, rack-cache-1.2, rack-ssl-1.3.2, rack-test-0.6.1, rails-3.2.8, rails-3.2.3, rails-settings-cached-0.2.1, railties-3.2.8, railties-3.2.3, rake-0.9.2.2, rdoc-3.12, ruby-readability-0.5.4, rvm-capistrano-1.2.7, sass-3.1.20, sass-rails-3.2.5, sprockets-2.1.3, sqlite3-1.3.6, subexec-0.2.2, swfobject-rails-1.1.1, therubyracer-0.10.1, thor-0.16.0, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, tzinfo-0.3.33, uglifier-1.2.5, warden-1.2.1] (Gem::LoadError)
from /home/passenger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /home/passenger/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem'
from /home/passenger/.rvm/gems/ruby-1.9.3-p194/bin/passenger:18:in `<main>'
from /home/passenger/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
from /home/passenger/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
While Passenger gem is installed (I used gem install passenger to install it) as you can see:
passenger#dragon:/usr/website/myapp/current$ gem list
*** LOCAL GEMS ***
actionmailer (3.2.3)
actionpack (3.2.3)
activemodel (3.2.3)
activerecord (3.2.3)
activeresource (3.2.3)
activesupport (3.2.3)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.0)
bundler (1.2.1)
cape (1.4.0)
capistrano (2.13.4)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.3.3)
daemon_controller (1.0.0)
devise (2.1.2)
devise_ldap_authenticatable (0.6.1)
erubis (2.7.0)
execjs (1.4.0)
fastthread (1.0.7)
file-tail (1.0.11)
guess_html_encoding (0.0.4)
high_voltage (1.1.1)
highline (1.6.15)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
jquery-rails (2.0.2)
jruby-pageant (1.1.1)
jsmin (1.0.1)
json (1.7.3)
libv8 (3.3.10.4 x86-linux)
mail (2.4.4)
mime-types (1.19)
mini_magick (3.4)
multi_json (1.3.6)
net-ldap (0.2.2)
net-scp (1.0.4)
net-sftp (2.0.5)
net-ssh (2.6.0)
net-ssh-gateway (1.1.0)
nokogiri (1.5.5)
orm_adapter (0.4.0)
passenger (3.0.17)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.3)
rails-settings-cached (0.2.1)
railties (3.2.3)
rake (0.9.2.2)
rdoc (3.12)
ruby-readability (0.5.4)
rubygems-bundler (1.1.0)
rvm (1.11.3.5)
rvm-capistrano (1.2.7)
sass (3.1.20)
sass-rails (3.2.5)
sprockets (2.1.3)
sqlite3 (1.3.6)
subexec (0.2.2)
swfobject-rails (1.1.1)
therubyracer (0.10.1)
thor (0.14.6)
tilt (1.3.3)
tins (0.5.5)
treetop (1.4.10)
tzinfo (0.3.33)
uglifier (1.2.5)
warden (1.2.1)
and here is my gem environment:
passenger#dragon:/usr/website/myapp/current$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [i686-linux]
- INSTALLATION DIRECTORY: /home/passenger/.rvm/gems/ruby-1.9.3-p194
- RUBY EXECUTABLE: /home/passenger/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /home/passenger/.rvm/gems/ruby-1.9.3-p194/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/passenger/.rvm/gems/ruby-1.9.3-p194
- /home/passenger/.rvm/gems/ruby-1.9.3-p194#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
and here is the rvm info:
passenger#dragon:/usr/website/myapp/current$ rvm info
ruby-1.9.3-p194:
system:
uname: "Linux dragon 3.2.0-26-generic-pae #41-Ubuntu SMP Thu Jun 14 16:45:14 UTC 2012 i686 i686 i386 GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.15.9 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "2 days 23 hours 20 minutes 14 seconds ago"
ruby:
interpreter: "ruby"
version: "1.9.3p194"
date: "2012-04-20"
platform: "i686-linux"
patchlevel: "2012-04-20 revision 35410"
full_version: "ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]"
homes:
gem: "/home/passenger/.rvm/gems/ruby-1.9.3-p194"
ruby: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194"
binaries:
ruby: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194/bin/ruby"
irb: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194/bin/irb"
gem: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194/bin/gem"
rake: "/home/passenger/.rvm/gems/ruby-1.9.3-p194#global/bin/rake"
environment:
PATH: "/home/passenger/.rvm/gems/ruby-1.9.3-p194/bin:/home/passenger/.rvm/gems/ruby-1.9.3-p194#global/bin:/home/passenger/.rvm/rubies/ruby-1.9.3-p194/bin:/home/passenger/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
GEM_HOME: "/home/passenger/.rvm/gems/ruby-1.9.3-p194"
GEM_PATH: "/home/passenger/.rvm/gems/ruby-1.9.3-p194:/home/passenger/.rvm/gems/ruby-1.9.3-p194#global"
MY_RUBY_HOME: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194"
IRBRC: "/home/passenger/.rvm/rubies/ruby-1.9.3-p194/.irbrc"
RUBYOPT: ""
gemset: ""
And here is the method (Line 247) that throws the error:
1 require "rubygems/requirement"
2
3 ##
4 # The Dependency class holds a Gem name and a Gem::Requirement.
5
6 class Gem::Dependency
7
8 ##
9 # Valid dependency types.
10 #--
11 # When this list is updated, be sure to change
12 # Gem::Specification::CURRENT_SPECIFICATION_VERSION as well.
13
14 TYPES = [
15 :development,
16 :runtime,
17 ]
18
19 ##
20 # Dependency name or regular expression.
21
22 attr_accessor :name
23
24 ##
25 # Allows you to force this dependency to be a prerelease.
26
27 attr_writer :prerelease
28
29 ##
30 # Constructs a dependency with +name+ and +requirements+. The last
31 # argument can optionally be the dependency type, which defaults to
32 # <tt>:runtime</tt>.
33
34 def initialize name, *requirements
35 if Regexp === name then
36 msg = ["NOTE: Dependency.new w/ a regexp is deprecated.",
37 "Dependency.new called from #{Gem.location_of_caller.join(":")}"]
38 warn msg.join("\n") unless Gem::Deprecate.skip
39 end
40
41 type = Symbol === requirements.last ? requirements.pop : :runtime
42 requirements = requirements.first if 1 == requirements.length # unpack
43
44 unless TYPES.include? type
45 raise ArgumentError, "Valid types are #{TYPES.inspect}, "
46 + "not #{type.inspect}"
47 end
48
49 #name = name
50 #requirement = Gem::Requirement.create requirements
51 #type = type
52 #prerelease = false
53
54 # This is for Marshal backwards compatibility. See the comments in
55 # +requirement+ for the dirty details.
56
57 #version_requirements = #requirement
58 end
59
60 ##
61 # A dependency's hash is the XOR of the hashes of +name+, +type+,
62 # and +requirement+.
63
64 def hash # :nodoc:
65 name.hash ^ type.hash ^ requirement.hash
66 end
67
68 def inspect # :nodoc:
69 "<%s type=%p name=%p requirements=%p>" %
70 [self.class, self.type, self.name, requirement.to_s]
71 end
72
73 ##
74 # Does this dependency require a prerelease?
75
76 def prerelease?
77 #prerelease || requirement.prerelease?
78 end
79
80 def pretty_print q # :nodoc:
81 q.group 1, 'Gem::Dependency.new(', ')' do
82 q.pp name
83 q.text ','
84 q.breakable
85
86 q.pp requirement
87
88 q.text ','
89 q.breakable
90
91 q.pp type
92 end
93 end
94
95 ##
96 # What does this dependency require?
97
98 def requirement
99 return #requirement if defined?(#requirement) and #requirement
100
101 # #version_requirements and #version_requirement are legacy ivar
102 # names, and supported here because older gems need to keep
103 # working and Dependency doesn't implement marshal_dump and
104 # marshal_load. In a happier world, this would be an
105 # attr_accessor. The horrifying instance_variable_get you see
106 # below is also the legacy of some old restructurings.
107 #
108 # Note also that because of backwards compatibility (loading new
109 # gems in an old RubyGems installation), we can't add explicit
110 # marshaling to this class until we want to make a big
111 # break. Maybe 2.0.
112 #
113 # Children, define explicit marshal and unmarshal behavior for
114 # public classes. Marshal formats are part of your public API.
115
116 if defined?(#version_requirement) && #version_requirement
117 version = #version_requirement.instance_variable_get :#version
118 #version_requirement = nil
119 #version_requirements = Gem::Requirement.new version
120 end
121
122 #requirement = #version_requirements if defined?(#version_requirements)
123 end
124
125 def requirements_list
126 requirement.as_list
127 end
128
129 def to_s # :nodoc:
130 if type != :runtime then
131 "#{name} (#{requirement}, #{type})"
132 else
133 "#{name} (#{requirement})"
134 end
135 end
136
137 ##
138 # Dependency type.
139
140 def type
141 #type ||= :runtime
142 end
143
144 def == other # :nodoc:
145 Gem::Dependency === other &&
146 self.name == other.name &&
147 self.type == other.type &&
148 self.requirement == other.requirement
149 end
150
151 ##
152 # Dependencies are ordered by name.
153
154 def <=> other
155 self.name <=> other.name
156 end
157
158 ##
159 # Uses this dependency as a pattern to compare to +other+. This
160 # dependency will match if the name matches the other's name, and
161 # other has only an equal version requirement that satisfies this
162 # dependency.
163
164 def =~ other
165 unless Gem::Dependency === other
166 return unless other.respond_to?(:name) && other.respond_to?(:version)
167 other = Gem::Dependency.new other.name, other.version
168 end
169
170 return false unless name === other.name
171
172 reqs = other.requirement.requirements
173
174 return false unless reqs.length == 1
175 return false unless reqs.first.first == '='
176
177 version = reqs.first.last
178
179 requirement.satisfied_by? version
180 end
181
182 def match? name, version
183 return false unless self.name === name
184 return true if requirement.none?
185
186 requirement.satisfied_by? Gem::Version.new(version)
187 end
188
189 def matches_spec? spec
190 return false unless name === spec.name
191 return true if requirement.none?
192
193 requirement.satisfied_by?(spec.version)
194 end
195
196 ##
197 # Merges the requirements of +other+ into this dependency
198
199 def merge other
200 unless name == other.name then
201 raise ArgumentError,
202 "#{self} and #{other} have different names"
203 end
204
205 default = Gem::Requirement.default
206 self_req = self.requirement
207 other_req = other.requirement
208
209 return self.class.new name, self_req if other_req == default
210 return self.class.new name, other_req if self_req == default
211
212 self.class.new name, self_req.as_list.concat(other_req.as_list)
213 end
214
215 def matching_specs platform_only = false
216 matches = Gem::Specification.find_all { |spec|
217 self.name === spec.name and # TODO: == instead of ===
218 requirement.satisfied_by? spec.version
219 }
220
221 if platform_only
222 matches.reject! { |spec|
223 not Gem::Platform.match spec.platform
224 }
225 end
226
227 matches = matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed
228 end
229
230 ##
231 # True if the dependency will not always match the latest version.
232
233 def specific?
234 #requirement.specific?
235 end
236
237 def to_specs
238 matches = matching_specs true
239
240 # TODO: check Gem.activated_spec[self.name] in case matches falls outside
241
242 if matches.empty? then
243 specs = Gem::Specification.all_names.join ", "
244 error = Gem::LoadError.new "Could not find #{name} (#{requirement}) amongst [#{specs}]"
245 error.name = self.name
246 error.requirement = self.requirement
247 raise error
248 end
249
250 # TODO: any other resolver validations should go here
251
252 matches
253 end
254
255 def to_spec
256 matches = self.to_specs
257
258 matches.find { |spec| spec.activated? } or matches.last
259 end
260 end
Did you make sure that passenger is in your Gemfile? I see you installed bundler and I think that is related to the ruby_noexec_wrapper in your stack trace.
Related
Unable to stub external request - Wrong regexp?
I'm trying to craft a stub_request that matches all requests to fcm.googleapis.com. Our backend is supposed to send a push notification to its users when new Posts or Comments is created. Our tests trigger a lot of requests to fcm.googleapis.com, that's why I need a generic matcher. EDIT: The test failed because I had added stub_request to the spec_helper. The failing test was not rspec, but an ordinary ActionController::TestCase test. My bad! :-| spec/spec_helper.rb 18 RSpec.configure do |config| 19 require_relative "../test/mock_helper" 20 require "webmock/rspec" 21 22 WebMock.disable_net_connect! 23 config.before(:each) do 24 stub_request(:post, "https://fcm.googleapis.com/fcm/send"). 25 with(body: /.*/). 26 to_return(status: 200) 27 But when I run the tests it does not look like WebMock cares about my stub_request. What might be wrong? Running tests Error: PostsControllerTest#test_should_create_post: WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST https://fcm.googleapis.com/fcm/send with body '{"registration_ids":[null],"notification": {"title":"Fred Flintstone har skrevet en melding i Bedrock Sportsballteam", "text":"New post!?"},"data":{"notification":{"avatar":null,"group_id":131900578, "issued_at":"2018-06-25T13:37:28.746+02:00", "full_name":"Fred Flintstone","id":700,"post_id":980190963, "role_id":1}}}' with headers {'Authorization'=>'key=KEY', 'Content-Type'=>'application/json'} You can stub this request with the following snippet: stub_request(:post, "https://fcm.googleapis.com/fcm/send"). with(:body => "{\"registration_ids\":[null],\"notification\": {\"title\":\"Fred Flintstone har skrevet en melding i Bedrock Sportsballteam\", \"text\":\"New post!?\"},\"data\":{\"notification\": {\"avatar\":null,\"group_id\":131900578, \"issued_at\":\"2018-06-25T13:37:28.746+02:00\", \"full_name\":\"Fred Flintstone\",\"id\":700,\"post_id\":980190963,\"role_id\":1}}}", :headers => {'Authorization'=>'key=KEY', 'Content-Type'=>'application/json'}). to_return(:status => 200, :body => "", :headers => {}) My backend should send a push notifiction to our users when a new Post is created updated. app/models/post.rb 16 class Post < ApplicationRecord 25 after_save :send_notifications 82 def send_notifications 83 PUSH_NOTIFICATIONS.new_post_in_group(post: self) 84 end bin/rails test test/controllers/posts_controller_test.rb:57 57 test "should create post" do 58 assert_difference("Post.count") do 59 assert_difference("PostImage.count", 3) do 60 post :create, params: { 61 group_id: groups(:sportsball).id, 62 post: { 63 text: "New post!?", 64 is_pinned: "true" 73 } 74 } 75 76 post = Post.last 77 assert_equal true, post.is_pinned 78 79 assert_response :created, response.body 80 assert valid_json?(response.body), "Invalid json: #{response.body}" 81 82 json = JSON.parse(response.body).deep_symbolize_keys 83 84 end 85 end 86 end PushNotifications class PushNotifications def initialize #fcm = FCM.new(ENV["FCM_SERVER_KEY"]) end def new_post_in_group(post:) registration_ids = all_users_except_author(post) author = post.user group = post.group return unless registration_ids options = { notification: { title: "#{author.name} har skrevet en melding i #{group.name}", text: post.text.truncate(27) }, data: { notification: { avatar: author.avatar, # comment_id: '646', group_id: group.id, issued_at: Time.now, full_name: author.name, id: 700, # 700 = new post. The client knows what to do by looking at this id. post_id: post.id, role_id: author.role_id(group) } } } response = #fcm.send(registration_ids, options) puts "Sendt: #{response}" if ENV["DEBUG"] end private def all_users_except_author(post) recipients = post.group.users.pluck(:fcm_token) recipients.delete(post.user.id) recipients end end config/initializers/PushNotifications.rb 1 require "#{Rails.root}/lib/push_notifications" 2 3 puts "initialize PushNotifications" 4 PUSH_NOTIFICATIONS ||= PushNotifications.new
The test failed because I had added stub_request to the spec_helper. The failing test was not rspec, but an ordinary ActionController::TestCase test. My bad! :-|
Ruby > Psych -> How to parse yaml docs in to ruby objects
I'm trying to do the following: open and read a file with multiple yaml docs parse yaml docs into ruby objects print content of each ruby object and the code: yml_string = Psych.dump(File.read(infile)) Psych.load_stream(yml_string) .each do |mobj| puts "mobj:\n #{mobj}" end The puts prints the contents of the yml_string (multiple yaml docs) but it is one long string. How does one go about parsing each yaml doc from the yml_string and store them in to ruby objects? The contents of infile (based on OP's comment): --- member: country: AF phone1: 60 223-4564 phone2: +93 799 123-456 --- member: country: BR phone1: +55 55 2000 3456 phone2: 55 9000 1234 --- member: country: CA phone1: 604 423-4567 phone2: +1 604 423-4567
This is what I ended up with yaml_hash = Psych.load_stream(File.read(infile)) yaml_hash.each do |member| mem = Hash[member['member']] end Thank you for all your help.
require 'yaml' require 'pp' infile = "test.yml" pp YAML.load_stream(File.read(infile)) # [{"member"=> # {"country"=>"AF", "phone1"=>"60 223-4564", "phone2"=>"+93 799 123-456"}}, # {"member"=> # {"country"=>"BR", "phone1"=>"+55 55 2000 3456", "phone2"=>"55 9000 1234"}}, # {"member"=> # {"country"=>"CA", "phone1"=>"604 423-4567", "phone2"=>"+1 604 423-4567"}}] On recent MRI psych is the same as yaml lib p [RUBY_VERSION, YAML == Psych] ["2.0.0", true] p [RUBY_VERSION, YAML == Psych] ["1.9.3", true]
Why is Ruby Bignum not working? [duplicate]
This question already has answers here: Exponentiation in Ruby 1.8.7 Returns Wrong Answers (5 answers) Closed 9 years ago. Here is what I have: Using temporary variables, I have: Why do 10 ** 18 and 10 ** 20 work fine, but 10 ** 19 doesn't?
It was a bug in Ruby 1.8.7. It has been fixed by this commit. Just upgrade to the latest version and everything will work fine. Here are some tests on 1.9.3: Here is the text representation (for blind users): 1.9.3p362 :001 > 10 ** 18 => 1000000000000000000 1.9.3p362 :002 > 10 ** 19 => 10000000000000000000 1.9.3p362 :003 > 10 ** 20 => 100000000000000000000 1.9.3p362 :004 > 10 ** 21 => 1000000000000000000000 1.9.3p362 :005 > 10 ** 22 => 10000000000000000000000 1.9.3p362 :006 > 10 ** 23 => 100000000000000000000000 Here's the list of commands I've run: irb 10 ** 18 10 ** 19 10 ** 20 10 ** 21 10 ** 22 10 ** 23
csv.foreach stuck, not calling the block
I am trying to write a CSV "fixer". Unfortunately It seems that the csv.foreach instruction is not calling the lambda I have created. The CPU is used at 100%. Just wondering what ruby is doing in the meantime... Any ideas why my code is wrong? 1 require "csv" 2 3 ARGV.empty? do 4 print "usage: fixcsv.rb <filename>" 5 exit 6 end 7 8 filename_orig = Dir.pwd + "/" + ARGV[0] 9 filename_dest = filename_orig.sub(/csv$/,"tmp.csv") 10 topic = filename_orig.sub(/_entries.csv$/,"").sub(/.*\//,"") 11 12 puts "topic:" + topic 13 14 writer = CSV.open(filename_dest,"w",:col_sep=>";") 15 #i=0 16 cycler = lambda do |row| 17 #i = i + 1 18 #puts "row number:" + i.to_str 19 #row[17] = topic 20 puts "foo" 21 writer << row 22 end 23 24 begin 25 CSV.foreach(filename_orig,:col_sep=>",",&cycler) 26 rescue 27 puts "exception:" + $!.message 28 exit 29 else 30 writer.close 31 end Here is the stack trace produced when I Ctrl-C it: stab#ubuntu:~/wok$ ruby addtopic.rb civilpoliticalrights_entries.csv topic:civilpoliticalrights ^C/usr/lib/ruby/1.8/csv.rb:914:in `buf_size': Interrupt from /usr/lib/ruby/1.8/csv.rb:825:in `[]' from /usr/lib/ruby/1.8/csv.rb:354:in `parse_body' from /usr/lib/ruby/1.8/csv.rb:227:in `parse_row' from /usr/lib/ruby/1.8/csv.rb:637:in `get_row' from /usr/lib/ruby/1.8/csv.rb:556:in `each' from /usr/lib/ruby/1.8/csv.rb:531:in `parse' from /usr/lib/ruby/1.8/csv.rb:311:in `open_reader' from /usr/lib/ruby/1.8/csv.rb:94:in `foreach' from addtopic.rb:25 EDIT: Ruby version is: $ ruby --version ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
Your program worked fine for me in Ruby 1.9. I have a few observations: If your input pathname does not end in csv, then the input and output file names will be the same. This could easily produce an infinite loop. You are definitely using the 1.9 flavor of csv. If this program needs to run on 1.8.7 it would need to have patches from the snippet below... Mods for 1.8.7: writer = CSV.open(filename_dest, "w", ?;) #i=0 cycler = lambda do |row| #i = i + 1 #puts "row number:" + i.to_str #row[17] = topic writer << row end begin CSV.open filename_orig, 'r', ?,, &cycler The main problem with 1.8.7 csv is that the interfaces to CSV.open and CSV.foreach do not take Hash options. Worse, they are expecting numeric code points, a feature of Ruby that apparently didn't work out and was withdrawn in 1.9.
DateTime formatting Rails
I have "Date.today + 2.days" I need to format it using .strftime, but with the "+2.days" it doesn't recognize that method.Any ideas?
Those nice helpers don't come with a vanilla ruby install. You need the activesupport gem (part of Ruby on Rails). $ gem install activesupport $ irb ruby-1.8.7-p249 > require 'rubygems' => true ruby-1.8.7-p249 > require 'active_support' => true ruby-1.8.7-p249 > Date.today => Fri, 16 Jul 2010 ruby-1.8.7-p249 > Date.today + 2.days => Sun, 18 Jul 2010
I don't see a problem, worked fine for me. (Date.today + 2.days).strftime #=> "2010-07-18"