Kaminari params on first page config option - ruby-on-rails

I am trying to set this option to true as described in the documentation. I used rails g kaminari:config which generated the following kaminari_config.rb :
Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
The params_on_first_page option not being present, I tried to add it before the end, this way : config.params_on_first_page = true
However, this doesn't seem to work, and I can't launch my rails server anymore. It gives me the following error :
Exiting
/home/vincent/workspace/bam-rails/config/initializers/kaminari_config.rb:10:in block in <top (required)>': undefined methodparam_on_first_page=' for #Kaminari::Configuration:0x0055c09deaddb0 (NoMethodError)
Did you mean? param_name=
I am using the version 0.17.0 of Kaminari. Am I missing something ?
Thank you in advance for your help.

Solved here : https://github.com/amatsuda/kaminari/issues/831
I missed to add github: "amatsuda/kaminari" in my Gemfile, whereas the option was only available on branch master.

Related

rails custom_configuration gem produces empty orderedoptions

Ruby 2.1.5
Rails 4.0.13
Using the custom_configuration gem, I get unexpected results.
config/environments/development.rb
JumboSIP::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
module Devise
module LdapAdapter
def self.valid_credentials?(login, password)
return true
end
end
end
config.cache_store = :memory_store
config.log_level = :debug
config.assets.compile = true
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
[..etc]
# ------------------------------------
# Application-specific configuration
# ------------------------------------
# use active directory auythentication (only for production)
config.x.use_ad_auth = false
# Enable to create cockpit cache files
config.x.cockpit_cache_enabled = false
config/initializers/scheduler.rb
if Rails.configuration.x.cockpit_cache_enabled
Rails.logger.info 'Initializing Cockpit Cache Scheduler'
puts 'Initializing Cockpit Cache Scheduler'
The code in the if is reached while it should not.
Debug inspection shows that
Rails.configuration.x.cockpit_cache_enabled evaluates to Empty ActiveSupport:OrderedOptions.
Rails.configuration.x is of type CustomConfiguration::Configuration
I checked I am actually in development environment.
Any clue as to why this happens? Any conflicts with other gems?
If I uses orderedoptions outside this gem, behaviour is as expected
It's two months delayed, but I ran into the same issue. The custom_configuration gem expects the options to be namespaced under another hash. Instead of:
config.x.cockpit_cache_enabled = false
try:
config.x.cockpit.cache_enabled = false
Now you should be able to access the value with:
Rails.configuration.x.cockpit.cache_enabled

How to initialize recaptcha in rails app?

I used the following guide: http://www.tweetegy.com/2012/10/setting-up-a-captcha-with-recaptcha-service-and-the-captcha-gem/
I have the following in development.rb:
ENV['RECAPTCHA_PUBLIC_KEY'] = 'keyString'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'keyString'
In config/initializers/recaptcha.rb:
Recaptcha.configure do |config|
config.public_key = RECAPTCHA_PUBLIC_KEY
config.private_key = RECAPTCHA_PRIVATE_KEY
end
I get the following error when I run rails server in development:
Exiting
/home/action/visualhaggard.org/config/initializers/recaptcha.rb:2:in `block in <top (required)>': uninitialized constant RECAPTCHA_PUBLIC_KEY (Nam
eError)
Has anyone encountered and solved this problem? Do I have a typo? Thanks.
The example doesn't define the RECAPTCHA_PUBLIC_KEY in an environment variable. It just defines it as a constant.
#put this in development.rb and in production.rb (separate keys in each so you can test!)
RECAPTCHA_PUBLIC_KEY= 'your-public-key'
RECAPTCHA_PRIVATE_KEY= 'your-private-key'

Why is DelayedJob is ignoring delayed_job_config.rb?

I have the following:
/config/delayed_job_config.rb
# Enable DelayedJob Logging
Delayed::Worker.logger = Rails.logger
Delayed::Worker.logger.auto_flushing = 1
# Do not delete failed jobs (default is true)
Delayed::Worker.destroy_failed_jobs = false
# Dont wait so long between jobs
Delayed::Worker.read_ahead = 100 # default was 5
Delayed::Worker.sleep_delay = 1 #default was 5
Problem here is the settings are not being used:
$ rails c
Loading development environment (Rails 3.2.5)
1.9.3-p125 :001 > Delayed::Worker.read_ahead
=> 5
1.9.3-p125 :002 > Delayed::Worker.sleep_delay
=> 5
Any ideas what's wrong here? Thanks
The configuration goes in:
config/initializers/delayed_job_config.rb
Documentation is here.

Where should I configure rails gems?

For example, I use mobylette gem and it's documentation says that I can configure it like this.
mobylette_config do |config|
config[:fallback_chains] = { mobile: [:mobile, :html] }
config[:skip_xhr_requests] = false
config[:mobile_user_agents] = proc { %r{iphone}i }
end
Only problem is that, I don't know where to put that code. I tried creating new file config/initializers/mobylette.rb, but I got no method 'mobylette_config' error when starting rails server.
So where should I put these gem configurations and specifically in this case mobylette configuration?
That would be the conventional place to put it -- config/initializers
You can also check that its being loaded by putting in a logger.debug in the initializer
logger.debug 'LOADED mobylette configuration'
You can quickly test if there's another problem by putting the config in your environment.rb file (which is not where I'd leave it)
Both of those should give you some more info to debug
This had me pulling my hair out too. But digging around in the source on github:
https://github.com/tscolari/mobylette/blob/master/lib/mobylette/respond_to_mobile_requests.rb
I found this in the comments:
# Example Usage:
#
# class ApplicationController...
# include Mobylette::RespondToMobileRequests
# ...
# mobylette_config do |config|
# config[:fall_back] = :html
# config[:skip_xhr_requests] = false
# config[:mobile_user_agents] = proc { %r{iphone|android}i }
# config[:devices] = {cool_phone: %r{cool\s+phone} }
# end
# ...
# end

What happened to Mongoid.config.master.connection.host?

I am trying to get Carrierwave (0.5.1) to work with Mongoid (2.0.0.beta.20), Rails 3. I followed every step at this guide.
In config/initializers/carrierwave.rb, I have:
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid.database.name
config.grid_fs_host = Mongoid.config.master.connection.host
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads"
end
When I try to start my server (rails server). In the console, I get:
...config/initializers/carrierwave.rb:3:in `block in <top
(required)>': undefined method `host' for #<Mongo::Connection:
0x00000103802420> (NoMethodError)
I don't understand why I am getting this error. I've looked everywhere
and can't seem to locate why this is happening...
It seems, Mongoid.config.master.connection.host doesn't work anymore
in newer versions of Mongoid. Was this removed? What is the
replacement for this?
So far my workaround is the following code:
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid.database.name
config.grid_fs_host = 'localhost'
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads"
end
Line 3, should be: config.grid_fs_host = 'localhost'. <-- Is there a better way to dynamically indicate the host depending on environment?
Found out that the mongo gem has changed. So it now has to be:
config.grid_fs_host = Mongoid.database.connection.primary_pool.host

Resources