FriendlyId: undefined method `use_slug?' for nil:NilClass - ruby-on-rails

I am creating a new environment besides production. I copied all the configurations from my production environment, changing what needed to be changed.
As it is the servers do start, but when I do a query I get this exception:
NoMethodError (undefined method `use_slug?' for nil:NilClass):
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:65:in `slugged?'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:43:in `finder_class'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:37:in `finder'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:32:in `method_missing'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/slugged_model.rb:149:in `find_one'
app/controllers/home_controller.rb:5:in `index'
The line in question does this:
#page = Page.find("home")
I am using FriendlyId 2.3.4, and Rails 2.3.4. The code is the same for the production environment, and it's working just fine there, so I'm not really sure on what's going on here...I could see that the line where the exception gets raised does
friendly_id_config.use_slug?
so for a reason I'm not aware of friendly_id_config is nil.
Thanks for any guidance on this problem

I found a workaround to this issue by loading the server using the production environment.
I was trying to use a 'preprod environment, and somehow FriendlyId didn't like that strange environment.
Load the app using RAILS_ENV=production and it worked fine.
Not a solution, but at least could move on...

Related

Conflict between Rails Admin and Impressionist gems

I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.

Heroku Array Unshift Method Rails

I have a working rails app on my local machine. I updated my Heroku and started to test it. One of my views requires the controller to add elements to an array using unshift.
When I go to this view on the web, I get an error We're sorry, but something went wrong.
I went into $heroku logs and the most recent errors are:
2014-02-28T02:08:26.650021+00:00 app[web.1]: NoMethodError (undefined method `unshift' for #<ActiveRecord::AttributeMethods::Serialization::Attribute:0x007fe57862f588>):
2014-02-28T02:08:26.650021+00:00 app[web.1]: app/controllers/users_controller.rb:32:in `show'
Any ideas how to fix this?
my controller function looks like this:
#user.daily = #user.daily.unshift(day)
#user.daily is a serialized array
#Mhsmith21, if day is an object and if you are rails 4+ then my suggestion is to use build instead of unshift.
If you are using unshift to add the object on first position then use build and reverse the array.
As unshift does not work for ActiveRecord::Associations::CollectionProxy.

resque-web: NoMethodError at /failed undefined method `to_yaml'

Resque-web is up and running but when trying to view the failed jobs I get the following error:
NoMethodError at /failed
undefined method `to_yaml' for 3:Fixnum
The stack trace points to a 'to_yaml' call as mentioned in the error, it seems like resque-web is missing a requires. Has anyone else had this problem or know how to solve it?
Note: I'm running this locally on a rails 4 app.
You can see the reason here: https://github.com/resque/resque/issues/1143 -- it boils down to a temporary bug that is fixed, but not released yet. I fixed mine by adding
require 'yaml'
at the top of the server.rb file
note that the server.rb file on my machine was located at:
/usr/local/lib/ruby/gems/2.0.0/gems/resque-1.25.1/lib/resque/server.rb
your location may vary

SslRequirement.disable_ssl_check error undefined method?

I am working on an established project, Rails 3, and trying to turn of SSL in development. The following line in environments/development.rb generates an error.
config.after_initialize do
SslRequirement.disable_ssl_check = true
end
Error reads:
undefined method `disable_ssl_check=' for SslRequirement:Module (NoMethodError)
Any pointers to this?
Searches have revealed little so far.
Thank you
Based on the version number you provided (0.1.0) the problem is likely caused by the fact that you are using a different gem.
The one you use is ssl_requirement (repo), whereas the disable_ssl_check method is provided by bartt-ssl_requirement (repo). The latter one is actually a fork of the former one so you might try to upgrade.

Herkou class changes not detected

I'm using Herkou for some Rails 3 hosting. I have pushed code to Heroku, and I am getting the following error from the logs:
NoMethodError (undefined method `format_date' for #<Project:0x00000001938f40>):
This method does exist! I can for example so this:
$heroku console
>> Project.format_date('2011-07-07 10:50')
=> "2011-07-07"
So my code appears to be deployed. Project responds to format_date.
I also tried heroku restart with no success.
Can anyone help me? Any and all suggestions are appreciated!
Are you sure you are calling format_date on the class itself, like you do in your example, and not on an instance of the class? I.e. Project.new.format_date("2011-07-07 10:50")

Resources