-1

I am trying to add advanced search facilities to a Blacklight installation, but I know slim to nil about rails.

I am stuck in a (so far great) tutorial that states:

Turn this feature on by adding to your CatalogController definition:
self.search_params_logic << :add_advanced_parse_q_to_solr

I can find my CatalogController, but I have no clue where to put the "<< :add_advanced_parse_q_to_solr" thingie.

Is it a part of the class definition in the top? As it is now it says:

class CataligController < ApplicationController

Am I supposed to exchange the "< ApplicationController" with "<< :add_advanced_parse_q_to_solr", or should I just append it?

What does the ":" mean, and what does the "<<" mean?

If anyone have any good references to tutorials that can teach me these (I guess) basic syntaxes, please post them here - I would love to understand what I am doing instead of just copy/pasting me my way through!

hasse
  • 883
  • 2
  • 10
  • 24

2 Answers2

6

The added line should appear within your CatalogController definition, so...

class CatalogController < ApplicationController
  self.search_params_logic << :add_advanced_parse_q_to_solr

The < operation shows class inheritance in the first line. The << operation means add the value on the right as a new element to the array on the left. An equivalent way would be to use the array push method...

self.search_params_logic.push(:add_advanced_parse_q_to_solr)

Which brings us to the question about what . means... it simply means you're calling a method that is part of an object or object's class.

For example

"Hasse".downcase
=> "hasse"

Strings have a method downcase, and in the above line you're calling that method on the string and the result will be returned.

self.search_params_logic means you're calling a method on self (in this case, self is the CatalogController so you could have also done CatalogController.search_params_logic but it's not very elegant).

The search_params_logic returns an array and you can manipulate the array... add or remove elements, for example.

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53
  • 1
    I can't tell if this is sarcasm or not, but very full explanation +1 – Yule Jan 12 '16 at 11:13
  • Thanks for a thorough explanation. I knew what the "." meant, but not the ":". But thanks anyway. I will read up on Ruby right away! :-) – hasse Jan 12 '16 at 11:23
  • Ah, I misread your message... "." and ":" look very similar on my monitor! Anything with a leading `:` is a symbol, which is just a concept with a name. This video discusses symbols... it's not a perfect video but he does a good job... https://www.youtube.com/watch?v=mBXGBbEbXZY – SteveTurczyn Jan 12 '16 at 11:38
  • @Yule no sarcasm. :) – SteveTurczyn Jan 12 '16 at 11:41
2

Well, array << "something" is just adding of new element into the array. And :something - is a symbol. You should learn basic syntax of Ruby language before using Rails. Start from the official site: https://www.ruby-lang.org/en/.

kimrgrey
  • 562
  • 2
  • 10
  • 1
    Thanks to you too. And of course you are right - I should (and will) read up on Ruby. I just needed the darn thing to work, in order to do some frontend work on the markup and the js (which is my homeground). – hasse Jan 12 '16 at 11:27