wrong number of arguments (3 for 2) after upgrading from Rails 3.0.14 to Rails 3.1.4 - ruby-on-rails-3.1

Everything was working fine in Rails 3.0.14, but after changing
gem 'rails', '3.0.14' to gem 'rails', '3.1.4' and running bundle update rails I now get the following error:
Started GET "/" for 127.0.0.1 at 2012-03-16 11:11:44 -0400
Processing by PagesController#index as HTML
Completed 500 Internal Server Error in 54ms
ArgumentError (wrong number of arguments (3 for 2)):
app/controllers/application_controller.rb:37:in `customize_by_subdomain'```
The most popular answer seemed to be that sqlite3 needed to be updated, but I did bundle update sqlite3 and I still have the same problem.
Here is the full trace: https://gist.github.com/2050530
The method that it is complaining about looks like this:
35 def customize_by_subdomain
36 subdomain = (request.subdomain.present? && request.subdomain != 'www' && request.subdomain) || 'launch'
37 #current_org = Organization.find_by_subdomain(subdomain) || Organization.find_by_subdomain('launch')
38 end
I have looked at the multitude of similar questions and I not found anything that solves my problem. The closest was question to mine was: wrong number of arguments (3 for 1) after upgrading rails from 3.1.1 to 3.1.3 but I am using authlogic and the version I am using didn't change after upgrading rails.
The only other interesting thing is my entire test suite passes, except for one request/integration spec which goes through the process of creating a new user. It seems strange that my request specs work fine when I can't even access a page in development.
Any ideas on what I can do to get to the bottom of this?

It looks like your New Relic plugin may need to be updated to a new version. In your stacktrace, the first line is from the New Relic code in your plugins folder. From their site, it looks like they released new Rails 3.1-specific code:
http://blog.newrelic.com/2011/07/29/for-the-active-record-new-relic-support-for-rails-3-1-is-here/
In the blog post, they talk about changes to the way ActiveRecord does logging, and your exception was triggered on the log_with_instrumentation method.
It looks like now you should install it as a gem rather than a plugin:
https://github.com/newrelic/rpm
Hope this helps.

Related

Github pages Jekyll static blog outdated

I setup a Jekyll blog on Github-Pages 5 months ago. It was working at that time, and I though it would be a nice place to post things.
Long story short, I wrote a first post, but then I never used, until yesterday when I wanted to check that all was working fine, but it was not. I also could not run Jekyll locally.
I do not use ruby on my daily basis ,so they were outdated. I though maybe if I update it and generate the site again everything is going to be working fine.
I updated ruby from 2.1.2 to 2.2.1, and I tried other things to make it work. Now is working locally, but throwing this
Generating...
Defaults: An invalid front-matter default set was found:
[{"scope"=>{"path"=>"_posts/"}, "values"=>{"author"=>"Agustin Gambina"}}]
Defaults: An invalid front-matter default set was found:
[{"scope"=>{"path"=>"_posts/"}, "values"=>{"author"=>"Agustin Gambina"}}]
I also added a Gemfile to the root directory
source 'https://rubygems.org'
require 'json'
require 'open-uri'
versions = JSON.parse(open('https://pages.github.com/versions.json').read)
gem 'github-pages', versions['github-pages']
When I run
github-pages health-check
I get this
Checking domain littlebit.me...
Uh oh. Looks like something's fishy: Domain does not resolve to the GitHub Pages server
Does anyone know why it happened to me that is not working anymore? was because it was outdated and something changed?
thank you
You have an error in your _config.yml file :
-
-
scope:
path: "_posts/scala"
values:
author: Agustin Gambina
Must be :
-
scope:
path: "_posts/scala"
values:
author: Agustin Gambina
This is not a fatal error, so your site build, but your rule is not applied.
Concerning the health-check, it works for me as it checks littlebit.me that resolve to github IPs.
$: dig littlebit.me
...
littlebit.me. 1800 IN A 192.30.252.154
littlebit.me. 1800 IN A 192.30.252.153
If it doesn't work on your PC, you may have a DNS problem. Maybe you've set a bad value in your hosts file ?

Padrino Tutorial: Can't Modify Frozen String (Runtime Error)

I am following the Padrino tutorial from here:
https://www.padrinorb.com/guides/blog-tutorial
I am copy and pasting the commands but I quickly ran into an error I don't understand:
$ padrino g controller posts get:index get:show
create app/controllers/posts.rb
create app/views/posts
apply tests/shoulda
/Users/waprin/.rvm/gems/ruby-2.1.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators/controller.rb:66:in `prepend': can't modify frozen String (RuntimeError)
from /Users/waprin/.rvm/gems/ruby-2.1.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators/controller.rb:66:in `create_controller'
This might be a bit late, but in case anyone else runs across this error (and because I just worked through the same tutorial) I'll post anyway...
It looks like there's an issue when generating controllers if a test component is specified. In this case you're using shoulda, but the same happens when using rspec and maybe others. It's been reported as a bug: https://github.com/padrino/padrino-framework/issues/1850 and has been fixed, but isn't yet part of a stable release.
One option to fix this would be to change your Gemfile to work with the latest from their github repo. To do this delete your GemFile.lock file, and comment out the line under 'Padrino Stable Gem' in your GemFile:
gem 'padrino', '0.12.4'
then uncomment the line under 'Or Padrino Edge':
gem 'padrino', :github => 'padrino/padrino-framework'
then re-run bundle install.
Of course, you'll no longer be running the stable release, and that may come with other trade-offs.
As a side-note, I believe that the guide on that page is fairly out of date. I also needed to replace:
get :index do
#posts = Post.all(:order => 'created_at desc')
render 'posts/index'
end
with:
get :index, :provides => [:html, :rss, :atom] do
#posts = Post.order('created_at desc')
render 'posts/index'
end
in the Post controller as the active record interface has changed since the time that the guide was written.
I was able to sole this problem by simply going to padrino gem path.
For me it was:
/Users/ahmadhassan/.rvm/gems/ruby-2.2.0/gems/padrino-gen-0.12.4/lib/padrino-gen/generators
open controller.rb and change line number 61:
path = #controller
to
path = #controller.dup

Ruby, Sinatra and Passenger config on Apache

This is potentially a simple question but I wanted to ask to avoid running around in circles.
I have installed ruby 1.9.2 on Ubuntu and have set up passenger to run with Apache 2.2 on the machine. I am getting the following error when I view the site:
Permission denied - log/sinatra.log
I have changed the permissions for the log directory, but still no luck. The full trace from passenger can be seen on the site page: http://monkeh.me/
Does anyone know if/what I've done wrong or what's happening?
Many thanks
EDIT
I have discovered that the site runs well using WEBrick on port 4567 on the production server, but the same code errors using Passenger. I have added to show exceptions for errors, so am now getting the following:
NoMethodError at /
undefined method `include?' for nil:NilClass
file: resource.rb location: block in attributes= line: 332
You can see this here: http://www.monkeh.me/?url=http://www.google.co.uk
Any ideas? Please help :)
The new issue with the nil class was due to not finalizing the classes properly. I needed to add the following after the models were loaded:
DataMapper.finalize
Thanks to #Frost for his continued help within the comments.

Job handler serialization incorrect when running delayed_job in production with Thin or Unicorn

I recently brought delayed_job into my Rails 3.1.3 app. In development
everything is fine. I even staged my DJ release on the same VPS as my
production app using the same production application server (Thin),
and everything was fine. Once I released to production, however, all
hell broke loose: none of the jobs were entered into the jobs table
correctly, and I started seeing the following in the logs for all
processed jobs:
2012-02-18T14:41:51-0600: [Worker(delayed_job host:hope pid:12965)]
NilClass# completed after 0.0151
2012-02-18T14:41:51-0600: [Worker(delayed_job host:hope pid:12965)] 1
jobs processed at 15.9666 j/s, 0 failed ...
NilClass and no method name? Certainly not correct. So I looked at the
serialized handler on the job in the DB and saw:
"--- !ruby/object:Delayed::PerformableMethod\nattributes:\n id: 13\n
event_id: 26\n name: memememe\n api_key: !!null \n"
No indication of a class or method name. And when I load the YAML into
an object and call #object on the resulting PerformableMethod I get
nil. For kicks I then fired up the console on the broken production
app and delayed the same job. This time the handler looked like:
"--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/
ActiveRecord:Domain\n attributes:\n id: 13\n event_id: 26\n
name: memememe\n api_key: !!null \nmethod_name: :create_a\nargs: []
\n"
And sure enough, that job runs fine. Puzzled, I then recalled reading
something about DJ not playing nice with Thin. So, I tried Unicorn and
was sad to see the same result. Hours of research later and I think
this has something to do with how the app server is loading the YAML
libraries Psych and Syck and DJ's interaction with them. I cannot,
however, pin down exactly what is wrong.
Note that I'm running delayed_job 3.0.1 official, but have tried upgrading to
the master branch and have even tried downgrading to 2.1.4.
Here are some notable differences between my stage and production
setups:
In stage I run 1 Thin server on a TCP port -- no web proxy in front
In production I run 2+ Thin servers and proxy to them with Nginx.
They talk over a UNIX socket
When I tried unicorn it was 1 app server proxied to by Nginx over a
UNIX socket
Could the web proxying/Nginx have something to do with it? Please, any insight is greatly appreciated. I've spent a lot of time
integrating delayed_job and would hate to have to shelve the work or, worse,
toss it. Thanks for reading.
I fixed this by not using #delay. Instead I replaced all of my "model.delay.method" code with custom jobs. Doing so works like a charm, and is ultimately more flexible. This fix works fine with Thin. I haven't tested with Unicorn.
I'm running into a similar problem with rails 3.0.10 and dj 2.1.4, it's most certainly a different yaml library being loaded when running from console vs from the app server; thin, unicorn, nginx. I'll share any solution I come up with
Ok so removing these lines from config/boot.rb fixed this issue for me.
require 'yaml'
YAML::ENGINE.yamler = 'syck'
This had been placed there to fix an YAML parsing error, forcing YAML to use 'syck'. Removing this required me to fix the underlying issues with the .yml files. More on this here
Now my delayed job record handlers match between those created via the server (unicorn in my case) and the console. Both my server and delayed job workers are kicked off within bundler
Unicorn
cd #{rails_root} && bundle exec unicorn_rails -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"
DJ
export LANG=en_US.utf8; export GEM_HOME=/data/reception/current/vendor/bundle/ruby/1.9.1; cd #{rail
s_root}; /usr/bin/ruby1.9.1 /data/reception/current/script/delayed_job start staging

How can fixtures be replaced with factories using rails3-generators?

I'm trying to replace fixture generation with factories using rails3-generators:
https://github.com/indirect/rails3-generators#readme
The gem is included in my Gemfile and has been installed:
# Gemfile
gem 'rails3-generators', :group => :development
I added the following to application.rb:
# application.rb
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl
end
Yet 'rails g model Insect' is still generating fixtures ('insects.yml'). Is this working for others using Rails 3.0.4 and rails3-generators 0.17.4?
'rails g' shows the new generators available (such as Authlogic and Koala), but 'rails g model' still lists fixtures and doesn't refer to factories.
What else should I add to get this to work? Thanks.
Edit: I ran the gem's test suite, which includes a test for this, and it passes. No clue why it doesn't work with my app.
Edit2: I tried again with a test project and get the same result: fixtures instead of factories. If anybody could confirm whether this works for them with Rails 3.0.4 and rails3-generators 0.17.4, that would be helpful too because it would imply that I'm doing something wrong with my projects.
Edit3: It works if I run 'rails g model Insect -r factory_girl'. I thought the generator configuration in application.rb was supposed to take care of that, so this seems to be the source of the problem.
Searching around I found the following, which may help:
Try specifying a directory option for factory_girl's factories:
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl, :dir => "spec/factories" # or test/factories, as the case may be
end
If you're using Test::Unit, try the following:
config.generators do |g|
g.stylesheets false
g.test_framework :test_unit, :fixture_replacement => :factory_girl
end
In both cases you will still need the rails3-generators gem, although there is a push to get that functionality into factory_girl_rails.
This Rails bug indicates that, at some point, the g.fixture_replacement code may not have worked right. Perhaps a test in 3.0.5 is in order. :)
A short update 9 years later:
instead of "factory_girl_rails" (which is deprecated now) use "factory_bot_rails".
Now, the factory gets created automagically:
$ rails g model tester name:string
Running via Spring preloader in process 31467
invoke active_record
create db/migrate/20200327152901_create_testers.rb
create app/models/tester.rb
invoke rspec
create spec/models/tester_spec.rb
invoke factory_bot
create spec/factories/testers.rb
I use rails 5.2.4, but this should also work with rails 6.

Resources