This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/intermediate-part-4
Using Rails 4:
For the controller section at around the 40min mark, I had to use this:
class SearchesController < ApplicationController
def show
@search = Search.new(term: params[:search][:term])
end
end
using [:search][:term]
to parse these params:
Parameters: {"utf8"=>"✓", "search"=>{"term"=>"ruby"}, "commit"=>"Search"}
For the solr reindex method at around 55min mark, I got this
error:
NoMethodError: undefined method `attr_accessible' for TextShout(id: integer, body: string):Class
which I solved by using the ‘protected_attributes’ gem.
Also, remember to run rake sunspot:solr:stop
after you’re done.
At ~55 minutes in, after installing the sunspot gems you may need to restart your rails server/console. Reload! (like in the video) wasn’t enough for me (in console).
In Rails 4, use include ActiveModel::Conversion
, instead of extend ActveModel::Naming
.
I like the last peace of this episode where you talked about searching approaches for polymorphic fields, pretty interesting.
I tried adding your updated show method in the search_controller.rb, however I get the following:
Circular dependency detected while autoloading constant SearchesController
I get the same params as you, but it’s not working. Not sure what I’m doing wrong.
Around the 55 minute mark, I was getting an error when I tried to reindex shouts in the console. Using Shout.index
worked for me, instead of Shout.reindex
. You’ll likely want to do this the first time, only.
I keep getting the following error after installing Sunspot_Solr
RSolr::Error::ConnectionRefused: Connection refused
I’ve followed the steps closely. I even had to install Java runtime and have gotten the error both in localhost and in the terminal. I’ve changed the port with no success. I’ve restarted the rake task to no avail. Wondering if anyone could shed light on this issue.
Ok figured it out I think, had to install JDK not JRE. I did
bundle exec rake sunspot:solr:run
and got
Java not found, or an error was encountered when running java.
A working Java 7 or later is required to run Solr!
Please install Java or fix JAVA_HOME before running this script.
Command that we tried: 'java -version'
Installing the JDK removed this message.
The text_shout aspect of the search is working but I’m not getting any results for the photo_shouts. My image method in the PhotoShout model is just
def index image_file_name end
Is there something else I’m missing?