Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:26:43+00:00 2026-05-22T12:26:43+00:00

After a long conversation with the fine people at IndexTank, I was not really

  • 0

After a long conversation with the fine people at IndexTank, I was not really sure on how to fix my problem, and I was wondering if anyone could help me.

I have an article model that belongs to a user model. This article model also has a boolean attribute called anonymous, which, if set to true gives the user the option to post the article without his name being shown.

Article
belongs_to :user
attr_accesible :anonymous, :user_id

User
has_many :articles

My problem is that if the article is posted as anonymous. I don’t want tanker to search within the author name field, but I want it searching every other field. I tried to do this with an if else statement where I would normally put the “tankit” block, but that does not work.

Is there a way I could put the tankit block into a model method and use a validation call back like this?

def anon_index
    if self.anonymous
      tankit 'my_index' do
        indexes VARIABLES ETC BUT NOT the user_ attributes
      end
    else # if anonymous is false
      tankit 'my_index' do
        indexes :title
        indexes :body
        indexes :user_penname
        indexes :user_firstname
        indexes :user_lastname
      end
    end
  end

I was thinking either this or putting an if else statement where the “tankit” block declaration goes, but neither of those seem to, unless I’m doing something wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:26:44+00:00Added an answer on May 22, 2026 at 12:26 pm

    how does this look?:

    class Article < ActiveRecord::Base
    
     tankit 'my_index' do
           indexes :title
           indexes :body
           indexes :custom_penname
           indexes :custom_firstname
           indexes :custom_lastname
     end
    
     def custom_penname
       if self.anonymous
         'anonymous'
       else
         self.user_penname
       end
     end
    
     def custom_firstname
       #same for first name
     end
     def custom_lastname
       #same for last name
     end
    end
    

    Same approach, different scenario:

    https://github.com/adrnai/rails-3-tanker-demo/blob/master/app/models/comment.rb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After a long time searching and trying I'm asking now for help: My situation:
This might not be a programming question but I am posting it after long
After long searches, I succeed to delete a row in a jqgrid with form
After a long search I'm still confused about it although I found some related
After a long investigation on how to use TFS 2010 I started with the
How long after a document is fed to the Google Search Appliance using a
I am returning to C++ after a long absence and I am stumbling a
I'm currently re-engaging with Python after a long absence and loving it. However, I
I'm getting back in to Cocoa development on the Mac after a long stint
After searching a long time for a performance bug, I read about denormal floating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.