Kaminari wrong number of arguments (0 for 1) - ruby-on-rails-3

I'm using kaminari and bootstrap_kaminari gems in my app. Previously they worked fine, but now, I don't know if it was an update that I made, this error appears every time the method paginate is called:
ActionView::Template::Error (wrong number of arguments(0 for 1)):
7: -# per_page: number of items to fetch per page
8: -# remote: data-remote
9: %li{:class => "page#{' active' if page.current?}"}
10: = link_to page, page.current? ? "#" : url, {:remote => remote, :method => method, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
app/views/kaminari/bootstrap/_page.html.haml:10:in `method'
app/views/kaminari/bootstrap/_page.html.haml:10:in `_app_views_kaminari_bootstrap__page_html_haml___4572733049493505448_70240978127920'
app/views/kaminari/bootstrap/_paginator.html.haml:14:in `block (2 levels) in _app_views_kaminari_bootstrap__paginator_html_haml__2289167586420570675_70240961152960'
app/views/kaminari/bootstrap/_paginator.html.haml:12:in `block in _app_views_kaminari_bootstrap__paginator_html_haml__2289167586420570675_70240961152960'
app/views/kaminari/bootstrap/_paginator.html.haml:8:in `_app_views_kaminari_bootstrap__paginator_html_haml__2289167586420570675_70240961152960'
app/views/network/_job_offer_results.html.erb:74:in `_app_views_network__job_offer_results_html_erb___3561074850404149034_70240933051920'
app/views/network/job_offer_home.html.erb:60:in `_app_views_network_job_offer_home_html_erb___1400061891974561937_70240932539240'
I have no idea which method is supposed to take 1 argument but is taking 0. page.current?, page.next? or page.prev?
Thanks for your help

Related

rails_admin without devise

I'm having hard time getting rails_admin to work without devise.
I tried https://gist.github.com/Overbryd/1068094
as well removing all the devise related code from my user model and routes
However, I'm getting the following error:
ActionView::Template::Error (Could not find a valid mapping for # From here
6: - if _current_user
7: - if user_link = edit_user_link
8: %li= user_link
9: - if logout_path.present?
10: %li= link_to content_tag('span', t('admin.misc.log_out'), :class => 'label label-important'), logout_path, :method => Devise.sign_out_via
11: - if _current_user.respond_to?(:email) && _current_user.email.present?
devise (2.2.3) lib/devise/mapping.rb:42:in find_scope!'
/home/eugene/.bundler/ruby/1.9.1/rails_admin-75079da0906e/app/helpers/rails_admin/application_helper.rb:36:inlogout_path'
Assuming you have a route similar to this:
get "logout" => "sessions#destroy", as: "logout"
Then you can do this:
- if _current_user
- if user_link = edit_user_link
%li= user_link
%li= link_to content_tag('span', t('admin.misc.log_out'), class: 'label label-important'), '/logout'
That simply replaces the Devise nonsense with a link to your overall sessions destroy route. You can also delete the logout_path method in the Application Controller as well.

Rails 3 route Type Mismatch Error when requesting url for route with subdomain in Mailer view

I'm getting this error when requesting this route: direct_appointment_url(#appointment.uuid, :subdomain => #user.name)
direct_appointment_url(#appointment.uuid, :subdomain => #user.name)
TypeError: can't convert Array to String
from ...rvm/gems/ruby-1.9.3-p362#example/gems/actionpack-3.2.12/lib/action_dispatch/http/url.rb:55:in `match'
route is defined as: get "/appointment/:uuid" => "schedule#appointment", as: "direct_appointment"
The values of the two vars passed in to the route matcher are:
appointment.uuid => "a52aff80-5b83-0130-987f-0026080ebf68"
and
#user.name => "example"
More context:
ActionView::Template::Error (can't convert Array to String):
13: Message: <%= #appointment.client_message %>
14: <% end %>
15:
16: View online: <%= direct_appointment_url(#appointment.uuid, :subdomain => #user.name) %>
17:
18: To see your latest appointments, login at: <%= #login_url %>
19: Your username is: <%= #user.email %>
app/views/user_mailer/new_appointment_email.text.erb:16:in `_app_views_user_mailer_new_appointment_email_text_erb__686277782469675039_70200502266100'
app/mailers/user_mailer.rb:13:in `block in new_appointment_email'
app/mailers/user_mailer.rb:12:in `new_appointment_email'
app/controllers/appointments_controller.rb:43:in `block in create'
app/controllers/appointments_controller.rb:42:in `create'
Ah, so much for useful error messages!
looking at the source code for https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/url.rb at line 55, (although blank) the previous lines show the error that should have been raised:
if options[:host].blank? && options[:only_path].blank?
raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
end
once I specified a host, it worked:
direct_appointment_url(#appointment.uuid, :subdomain => "hello", :host
=> "blah")
=> "http://hello.blah/appointment/6a5cc9a0-5b8f-0130-9883-0026080ebf68"
Protip
Don't provide an array of possible hosts to your config file:
config.action_mailer.default_url_options = { :host => ['lvh.me:3000', 'blah.dev'] }

Rspec what is wrong with my test for create controller action?

I am trying to learn TDD and this is part of my homework I couldn't figure out how to do it.
I want to test create controller action, and here is my code for test:
require 'spec_helper'
describe MoviesController do
describe 'create' do
it 'should call the model method perform create!' do
Movie.should_receive(:create!).with({"title" => 'Milk', "rating" => 'R'})
post :create, :movie => {:title => 'Milk', :rating => 'R'}
end
end
end
But I got:
Failures:
1) MoviesController create should call the model method performe create!
Failure/Error: post :create, :movie => {:title => 'Milk', :rating => 'R'}
NoMethodError:
undefined method `title' for nil:NilClass
# ./app/controllers/movies_controller.rb:50:in `create'
# ./spec/controllers/movies_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
Finished in 0.21714 seconds
And here is create action I am testing against. Yes, it is TDD, and yes, I am testing a
working code, and it is the testing doesn't working :D
def create
#movie = Movie.create!(params[:movie])
flash[:notice] = "#{#movie.title} was successfully created."
redirect_to movies_path
end
I don't even know why I got the undefined method error message? I have a few other test passed but I deleted in this code snippe for simplicity, so I don't think it is related db/model related config problem. But why it does not working and how to change it?
Cheers
When you do a should_receive like that, it will return nil so the next line (when setting the flash message) attempts to retrieve the title from nil. Change your should_receive to:
Movie.should_receive(:create!).with({"title" => 'Milk', "rating" => 'R'}).and_return(stub_model(Movie))

Resque is returning Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM `users`

Resque is returning Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM users
Worker
8608f362-819b-4c15-b42b-69c4df00d27b:1 on low at about 16 hours ago
Class
AddLiveView
Arguments
4383
{"remote_ip"=>"184.72.47.71", "expires"=>true}
Exception
ActiveRecord::StatementInvalid
Error
Mysql2::Error: closed MySQL connection: SHOW FIELDS FROM `users`
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `query'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:473:in `columns'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `block (2 levels) in initialize'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `block in initialize'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `yield'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `default'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `block in initialize'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/base.rb:717:in `yield'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/base.rb:717:in `default'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/base.rb:717:in `columns_hash'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/locking/optimistic.rb:145:in `locking_enabled?'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/relation.rb:110:in `to_a'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:376:in `find_first'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:122:in `first'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/associations/singular_association.rb:42:in `find_target'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/associations/association.rb:146:in `load_target'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/associations/association.rb:56:in `reload'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/associations/singular_association.rb:9:in `reader'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/associations/builder/association.rb:41:in `block in define_readers'
/app/app/workers/add_live_view.rb:24:in `block in perform'
/usr/local/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
/app/app/workers/add_live_view.rb:13:in `perform'
My worker class looks like:
class AddLiveView
#queue = :low
def self.perform(song_id, options)
begin
song = Song.find(song_id)
current_user = User.find(options['current_user_id']) if !options['expires']
rescue
puts "Error #{$!}"
end
begin
Timeout.timeout(30.seconds) do
if options['expires']
# live_view = LiveView.add_live_view_that_expires(song, options['remote_ip'])
ip_to_country = IpToCountry.where('ip_to_countries.ip_number_to >= INET_ATON(?)', options['remote_ip']).order('ip_number_to ASC').limit(1).first
live_view = LiveView.new(:live_viewable => song, :live_viewable_category => 'View', :expires => true, :expires_at => 1.month.from_now, :ip => options['remote_ip'], :country_name => ip_to_country.country_name, :iso_two_letter_country_code => ip_to_country.iso_two_letter_country_code)
if live_view.save
Pusher["#{song.class.to_s.underscore}_#{song.id}"].trigger('live_view', {
:user => nil,
:live_viewable => live_view.live_viewable,
:artist => live_view.live_viewable.user
})
# We do this in the worker, because we want the live_view object to exist when we push it to our notification service
# Only keep data from last 30 days
LiveView.where('live_views.expires = ? AND live_views.expires_at < ?', true, Date.today).destroy_all
end
else
# ... do something else here ...
end
end
rescue Timeout::Error
end
end
end
In console, I tried doing it manually by doing:
song = Song.find(4383)
ip_to_country = IpToCountry.where('ip_to_countries.ip_number_to >= INET_ATON(?)', '184.72.47.71').order('ip_number_to ASC').limit(1).first
live_view = LiveView.new(:live_viewable => song, :live_viewable_category => 'View', :expires => true, :expires_at => 1.month.from_now, :ip => '184.72.47.71', :country_name => ip_to_country.country_name, :iso_two_letter_country_code => ip_to_country.iso_two_letter_country_code)
live_view.save
live_view.live_viewable.user
Everything works! Why does the error show up in production? Could this be that there are many connections hitting the db at the same time and the timeout limit is being reached?
Could this be that there are many connections hitting the db at the same time and the timeout limit is being reached?
That could be it. You can demonstrate something like it easily in Rails' console.
$ rails console
Loading development environment (Rails 3.2.2)
1.9.3-p125 :001 > require 'timeout'
=> true
1.9.3-p125 :002 > Timeout.timeout(1) { User.find_by_sql('SELECT sleep(2) FROM users;') }
User Load (974.4ms) SELECT sleep(2) FROM users;
: execution expired: SELECT sleep(2) FROM users;
ActiveRecord::StatementInvalid: : execution expired: SELECT sleep(2) FROM users;
from /Users/sluukkonen/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
# Skip the rest of the backtrace...
After this, every query to the database will raise a Mysql2::Error, as the connection is closed.
1.9.3-p125 :003 > User.count
Mysql2::Error: closed MySQL connection: SHOW FULL FIELDS FROM `users`
ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection: SHOW FULL FIELDS FROM `users`
from /Users/sluukkonen/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
# Again, skip the rest of the backtrace..
I'm not sure what the intended behavior is, so I can't say if there is a bug in Mysql2 or ActiveRecord, but using PostgreSQL with the pg gem doesn't exhibit similar behavior (subsequent queries are executed normally).
Adding reconnect: true to your database.yml should fix the problem, but note the caveats that adding it entails.

Unexpected rspec behavior Ruby on Rails Turorial chapter 12

I am seeing an error that is only dependent on the location of the line:
should change(Relationship, :count).by(-1)
For example, with the code:
it "should destroy a relationship using Ajax" do
lambda do
xhr :delete, :destroy, :id => #relationship
response.should be_success
end.should change(Relationship, :count).by(-1) #<<-line is here
I get the rspec error:
1) RelationshipsController DELETE 'destroy' should destroy a relationship using Ajax
Failure/Error: xhr :delete, :destroy, :id => #relationship
ActionView::MissingTemplate:
Missing template relationships/destroy with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, :html], :locale=>[:en, :en]} in view paths "#<RSpec::Rails::ViewRendering::PathSetDelegatorResolver:0x00000100a5b5f8>"
# ./app/controllers/relationships_controller.rb:16:in `destroy'
# ./spec/controllers/relationships_controller_spec.rb:44:in `block (4 levels) in <top (required)>'
# ./spec/controllers/relationships_controller_spec.rb:43:in `block (3 levels) in <top (required)>'
But with the code:
it "should destroy a relationship using Ajax" do
lambda do
xhr :delete, :destroy, :id => #relationship
response.should be_success
should change(Relationship, :count).by(-1) #<<-Line moved to here
end
... the test passes.
I am seeing expected behavior when I use a web browser. Unfollowing a user adjusts totals correctly.
So, are these two rspec tests not equivalent? Am I falsely reassured that the second test passes? If they are functionally equivalent, why does the first one fail?
Seems this was due, in part, to having confused
./app/controllers/relationships_controller.rb
with
./spec/controllers/relationships_controller_spec.rb
Code pasted into the wrong file (appropriately) generated no syntax errors. Fixing my error lead to passing rspec tests.