-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!

4

2 回答 2

6

添加的行应该出现在您的CatalogController定义中,所以...

class CatalogController < ApplicationController
  self.search_params_logic << :add_advanced_parse_q_to_solr

<操作在第一行显示类继承。该<<操作意味着将右侧的值作为新元素添加到左侧的数组中。一种等效的方法是使用数组推送方法...

self.search_params_logic.push(:add_advanced_pa​​rse_q_to_solr)

这给我们带来了关于什么.意思的问题……它只是意味着您正在调用一个作为对象或对象类的一部分的方法。

例如

"Hasse".downcase
=> "hasse"

字符串有一个方法小写,在上面的行中,您在字符串上调用该方法,结果将被返回。

self.search_params_logic意味着你正在调用一个方法self(在这种情况下,你也可以这样做self,但它不是很优雅)。CatalogControllerCatalogController.search_params_logic

返回一个数组,您可以操作该search_params_logic数组...例如添加或删除元素。

于 2016-01-12T10:53:30.890 回答
2

好吧,array << "something"只是将新元素添加到array. 和:something- 是一个符号。在使用 Rails 之前,您应该学习 Ruby 语言的基本语法。从官方网站开始:https ://www.ruby-lang.org/en/ 。

于 2016-01-12T10:43:01.287 回答