solidus_searchkick - undefined method `deep_symbolize_keys' - ruby-on-rails

I am using Solidus and I want to implement a better search wiht elasticsearch, I'm using solidus_searchkick to do that. But I get the following error:
undefined method 'deep_symbolize_keys' for #<ActionController::Parameters:0x0000556eae99cda8>
At Spree::HomeController#index, that has:
Spree::HomeController.class_eval do
def index
#searcher = build_searcher(params.merge(include_images: true))
#products = #searcher.retrieve_products
#taxonomies = Spree::Taxonomy.includes(root: :children)
end
end
I have NOT changed anything at Solidus' search options.
I get this error right after I run 'bundle install', installs everything just fine.
Then, I run 'rails s' and I get this error when I try to get my home or any other page that shows me any product.
Versions:
Rails: 5.1.6
Ruby: 2.5.1
solidus_searchkick: 0.3.4
Solidus: 2.5.0

This is an issue with the deprecated method deep_symbolize_keys in Rails 5.1. I just submitted a Pull Request for the solidus_searchkick gem. You can find it here https://github.com/elevatorup/solidus_searchkick/pull/6/files
If you point your solidus_searchkick gem to that branch it will work.

Related

Ruby: parametrize string without Ruby on rails framework (Jekyll plugin)

I have plugin that takes attribute from post's front matter and uses it in permalink. Problem is I need to clean up any accents and diacritics from the string before putting it in to the permalink. Ruby on rails has method called parametrize which does exactly what I need but I have no idea how to use it in plugin.
This is plugins code I have:
module JekyllCustomPermalink
class CustomPermalink < Jekyll::Generator
safe true
priority :low
def generate(site)
# nothing to do, wait for hook
end
Jekyll::Hooks.register :documents, :pre_render do |doc|
begin
# check if jekyll can resolve the url template
doc.url
rescue NoMethodError => error
begin
if !doc.collection.metadata.fetch("custom_permalink_placeholders").is_a?(Array)
raise CustomPermalinkSetupError, "The custom placeholders need to be an array! Check the settings of your '#{doc.collection.label}' collection."
end
def doc.url_template
#custom_url_template ||= collection.metadata.fetch("custom_permalink_placeholders").inject(collection.url_template){|o,m| o.sub ":" + m, data[m].to_s.parameterize}
end
rescue KeyError
# "custom_permalink_placeholders"
raise CustomPermalinkSetupError, "No custom placeholders defined for the '#{doc.collection.label}' collection. Define an array of placeholders under the key 'custom_permalink_placeholders'. \nCaused by: " + error.to_s
end
end
end
end
end
but I get this error:
john#arch-thinkpad ~/P/blog (master)> bundle exec jekyll serve --trace
Configuration file: /home/john/Projects/lyricall/_config.yml
Source: /home/john/Projects/lyricall
Destination: /home/john/Projects/lyricall/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
Liquid Exception: undefined method `parameterize' for "Žďořšťáčik":String in feed.xml
bundler: failed to load command: jekyll (/home/john/.gem/ruby/3.0.0/bin/jekyll)
/usr/lib/ruby/gems/3.0.0/gems/jekyll_custom_permalink-0.0.1/lib/jekyll_custom_permalink/custom_permalink.rb:20:in `block in url_template': undefined method `parameterize' for "Žďořšťáčik":String (NoMethodError)
What am I doing wrong ? How can I use this method which should be part of a string class but apparently it is not ? How can I achieve same result without ruby on rails framework ?
INFO:
jekyll 4.1.1
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
Thank you for help
Rails additions to base Ruby classes, like String#parameterize, are part of the Active Support Core Extensions. The activesupport gem can be installed and used independent of Rails.
To keep the default footprint low, ActiveSupport allows you to require only the individual extensions you want to use. In your case, you will need to require the string inflection extensions:
require 'active_support/core_ext/string/inflections'
"Kurt Gödel".parameterize
=> "kurt-godel"

Pagination issue: `map' : undefined method 'existent'

I just installed the will_paginate, 3.0.7 and bootstrap-will_paginate, 0.0.10 gem and when i call the following to get my articles paginated
def index
#articles = Article.paginate(page: params[:page], per_page: 5)
end
I get the following error upon attempting to launch the localhost server
/Users/Jack/.rvm/gems/ruby-2.3.1#global/gems/activesupport-5.0.0.1/lib/active_support/i18n_railtie.rb:45:in `map': undefined method `existent' for #<String:0x007fd4a2bfa5d0> (NoMethodError)
Did you mean? extend
What's going wrong?
This was an issue with earlier version of will_paginate with Rails 5.
You need to update your will_paginate gem to use latest updated one which is:
gem 'will_paginate', '3.1.5'
This issue has been fixed with this merge:
https://github.com/mislav/will_paginate/pull/450

Whois gem not working in rails

class DomaincheckerController < ApplicationController
def index
end
def store
r =Whois.whois(secure_params['domain'])
render :text => "#{r}"
end
private
def secure_params
params.require(:whois).permit(:domain)
end
end
This is my domainchecker controller. The index method renders a form. After submitting the form it goes to store method. Here I am trying to use the whois gem. I have installed whois gem by running gem install whois. But I am getting this error.
uninitialized constant DomaincheckerController::Whois
The problem is that you installed the gem directly and not using bundler, therefore the Rails app can't find the dependency.
In order to install a gem in a Rails project you need to edit the Gemfile file and add the gem there. Once added, run
$ bundle
in order to install the dependency. Check the documentation about the Gemfile.

Will_paginate gem is not installing - Rails 4

for something reason will_paginate is not installed.
i have put the line
gem 'will_paginate', '~>3.0.6'
in my gemfile,
i even ran "gem install will_paginate" in the console.
it says installed sucessfully but using the instructions to check if will_paginate is indeed install returns false nil
reference:
>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate
If any of these lines return nil/false, will_paginate has not properly loaded in your app.
and i get this error when implemented
undefined method `total_pages' for #<Post::ActiveRecord_Relation:0x007fa40773bc18>
UPDATE:
I specifically stated in my gemfile to install version 3.0.5 not the latest version(3.0.7) and the gem is loaded properly. BUT the error with the total_pages still remains.
more info:
controller:
#posts = Post.paginate(:page => params[:page])
view:
<%= will_paginate #posts %>
UPDATE 2:
FIXED the error (had a typo) BUT i cannot see visually the gem anywhere on the page.

Ransack with kaminari on rails 4.1 error with empty search string

I am using Ransack simple search with kaminari for pagination successfully on rails 4.0.4. I have upgraded rails with this project to 4.1.0, which is the only change, and now if I search without entering any inputs in the search form I get: undefined method `delete_if' for "":String This previously worked with the earlier version of rails!
#q = HouseDesign.search(params[:q])
#house_designs = #q.result
#q.sorts = 'price asc' if #q.sorts.empty?
#house_designs = #house_designs.page params[:page]
url when it errors note
q=?&page=2&q=&utf8=✓ 4.1.0
url when successful
?&page=2&utf8=✓ 4.0.4
This is only my second project in rails so I could be missing something but I have spent all day searching to no avail.
Looks like this was fixed in this commit: https://github.com/activerecord-hackery/ransack/commit/71021b558b26d31e4b3b4a03cd595efd35ad25c4
Try running the rails-4.1 branch. It's working for me with Rails 4.1 with this in my Gemfile:
gem 'ransack', :github => "activerecord-hackery/ransack", :branch => "rails-4.1"

Resources