searchlogic

How do you do this in mysql or rails

若如初见. 提交于 2020-01-03 05:50:08
问题 Say you have a posts table and a tags table, and both are related by a post_tags table. so posts has id/subject/body columns tags has id/name post_tags has id/post_id/tag_id in rails terminology, I have a Post Model that has many Tags through AssetTags. I'm trying to query for a post that has 2 specific tags. so if there is a rails tag and a mysql tag, I want a query that returns a post that only has those two tags. make sense? Any way to do this with activerecord (I'm using search logic) or

searchlogic and virtual attributes

99封情书 提交于 2019-12-19 12:09:11
问题 Let's say I have the following model: Person <AR def name [self.first_name,self.middle_name,self.last_name].select{|n| n.present?}.join(' ') end end How could I do a search on the virtual attribute with searchlogic, something like: Person.search.name_like 'foo' Of courese I could construct a large statement like: Person.search.first_name_like_or_last_name_like_or_... 'argh' but surely there is a more elegant way. 回答1: Searchlogic can be combined with existing named scopes and must be in case

search by attribute_like_any using multiple words in one field [searchlogic]

被刻印的时光 ゝ 提交于 2019-12-13 04:25:46
问题 My form <% form_for @search do |f| %> <%= f.input :name_like_any %> ... <% end %> Controller @search = Product.search @search.name_like_any(params[:search][:name_like_any].split(/\s+/)) @products = search.all This returns the correct result, but now my form shows the name as ["foo", "bar"] instead of what the user input ( "foo bar" ). What's the elegant way to handle this? Appreciate any feedback 回答1: Solution Well, I found out the hard way first, then by asking another question, I

Searchlogic OR condition results in undefined method

ε祈祈猫儿з 提交于 2019-12-11 17:47:18
问题 I'm sure that I'm overlooking something since this is my first time using Searchlogic. Whenever I use a statement like Listing.city_like_or_state_like(params[:search]) in my controller, Rails returns an "Undefined Method" error. I'm trying to search 2 fields within the same model. However, if I use Listing.city_like(params[:search]) everything is totally fine. Am I missing something here? I thought OR conditions could be chained together with Searchlogic. How can I implement an OR statement?

Searchlogic doesn't convert the time properly for datetime conditions

怎甘沉沦 提交于 2019-12-11 14:03:28
问题 The author of Searchlogic says that it is delegated to A::R converter, but at least in our case this didn't cover the usual cases. Local time was 'interpreted' as UTC and therefore was moved by one hour (CET). How can I do that properly? I add our current workaround as an answer, hopefully it helps somebody! 回答1: We've added the following method to the application controller: protected def parse_datetime_fields(hash, key) value = hash[key] return unless value hash[key] = Time.zone.parse(value

Reusing named_scope to define another named_scope

﹥>﹥吖頭↗ 提交于 2019-12-10 13:03:54
问题 The problem essence as I see it One day, if I'm not mistaken, I have seen an example of reusing a named_scope to define another named_scope. Something like this (can't remember the exact syntax, but that's exactly my question): named_scope :billable, :conditions => ... named_scope :billable_by_tom, :conditions => { :billable => true, :user => User.find_by_name('Tom') } The question is: what is the exact syntax, if it's possible at all? I can't find it back, and Google was of no help either.

Date conditions using Search logic

落爺英雄遲暮 提交于 2019-12-10 11:38:45
问题 The Rails plugin - Searchlogic, from binary logic - offers the ability to filter by date. I have my form set up like so... <% form_for @search do |f| %> <%= f.label :start %> <%= f.select :due_at_after, [[['','']],['November', '2009-11-01'.to_date],['December', '2009-12-01'.to_date]] %><br> <%= f.label :end %> <%= f.select :due_at_before, [[['','']],['December', '2009-12-01'.to_date],['January', '2010-01-01'.to_date]] %> <%= f.submit 'Search' %> <% end %> But, the date I'm getting back from

Rails: Stack level too deep error

允我心安 提交于 2019-12-07 05:31:46
问题 My rails app has 3 models. Trail, Region and Feature. I am able to interact with these models fine in my lib/tasks directory. I used anemone to crawl and populate the database. Examples of calls I made on the models: Trail.find_or_initialize_by_title(detail_title) I am now trying to write a controller that uses the model. class TrailController < ApplicationController def index render :json => Trail.all end end Now if i open rails console and try app.get('trail/index') I get a 500 return code

Rails: Stack level too deep error

社会主义新天地 提交于 2019-12-05 09:29:37
My rails app has 3 models. Trail, Region and Feature. I am able to interact with these models fine in my lib/tasks directory. I used anemone to crawl and populate the database. Examples of calls I made on the models: Trail.find_or_initialize_by_title(detail_title) I am now trying to write a controller that uses the model. class TrailController < ApplicationController def index render :json => Trail.all end end Now if i open rails console and try app.get('trail/index') I get a 500 return code and I see the following in my development.log SystemStackError (stack level too deep): app/controllers

How Do I get searchlogic to work with rails 3?

流过昼夜 提交于 2019-12-03 05:15:40
问题 I put searchlogic in my gemfile... and now my rails server won't start :( this is the errormessage gems/ruby-1.8.7-p299/gems/activesupport-3.0.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `merge_joins' for class `Class' (NameError) from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain' from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib