Scoping a sunspot solr search by text using a string field

Assuming the following sunspot setup of the post class:

class Post < ActiveRecord::Base
  searchable do
    text :title
    string :state
    integer :category_ids
  end
end

In Sunspot you can scope your search via the with method. It allows you to do stuff like:

Post.search {
  fulltext "your query", :fields => :title
  with(:category_ids).any_of([1,2,3,4,5])
}

If you want to scope your search based on a text field, you have to add another field of the type string (such as the state fi...

Git: When committing, check the diff

When committing, you should always check the diff of your changes so you don't include any leftovers or irrelevant/bad changes. Any time spent on that is well invested as it saves you rejected merge requests or any mess you need to clean up later.

While you can just use git diff or git diff --cached (to diff staged changes), you can also have Git include the changes as a comment below the commit message:

git commit -v

That will open up the usual commit "file" in your preferred text editor, but it will include a diff below the s...

Impressumspflicht bei Facebook & Twitter: Schnelle Info und Abhilfe

Jedes nicht rein private Profil auf Social Media Portalen muss ein Impressum haben, das heißt insbesondere Unternehmen und Freiberufler (§ 5 Abs.1 TMG). Wer das Impressum dort nicht unter einem eigene Button mit der Aufschrift “Impressum” oder “Kontakt” unterbringt, bietet eine große Angriffsfläche für Abmahner (Quelle: http://rechtsanwalt-schwenke.de/impressumspflicht-bei-google-plus-und-twitter/).

Hier also in kurzen Schritten, wie man ein Impressum erstellt und wie man es bei Facebook und Twitter einbindet:

#1. Impressum erstellen

Ic...

How to inspect controller filter chains in specs

Sometimes you need to look at the filter chain in specs. You can do it like that on Rails 2:

controller.class.filter_chain.map(&:method)

Note that we need to look at the controller's class since before_filter and after_filter stuff happens on the class level.

Also mind that the above code will give you all filters, both those run before and after an action. You can query before? and after? on the filter objects to scope down to only some of them:

controller.class.filter_chain.select(&:before?).map(&:method)

For Rails 3, ...

ActiveRecord::SpawnMethods

Methods to remove e.g. order or conditions from an existing scope chain.

SSL certificate problem, when trying to install the libyaml package

I was experiencing the following problem:

 It seems your ruby installation is missing psych (for YAML output). 
 To eliminate this warning, please install libyaml and reinstall your ruby

So I tried to install the libyaml package via:

rvm pkg install libyaml

This is when I experienced the SSL certification problem mentioned above. This happens when your RVM certificates have expired. You can fix this by updating them via:

 rvm get stable

After doing that curl could verify the SSL certificate and I w...

How to fix: Firefox uses incorrect fonts on all webpages, regardless of their CSS

If you encounter a Firefox that does not care about your font settings but always uses specific fonts, you can fix that. Usually this should not happen, as it's not a default setting:

  1. Open up the Preferences.
  2. Switch to "Content".
  3. In the "Fonts & Colors" section, click the "Advanced..." button.
  4. Tick "Allow pages to choose their own fonts, instead of my selection above".
  5. Confirm by pressing "OK".

![Screenshot](https://makandracards.com/makandra/10913-how-to-fix-firefox-uses-incorrect-fonts-on-all-webpages-regardless-of-their-c...

Rspec shared example group error: ensure_shared_example_group_name_not_taken

Never name your shared example group *_spec.rb. Otherwise rspec will try to load your example group as a spec and you will get the error above.

Understanding the Selenium error "Modal Dialog Present" (aka Selenium::WebDriver::Error::UnhandledAlertError)

So your Cucumber feature sometimes dies with this exception:

Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)

As a seasoned Selenium veteran you are used to misleading error messages. Hence you might be surprised that the reason for this particular error is that there is actually a modal dialog present and preventing Selenium from executing commands like click or page.have_css?.

How your code triggers this issue

The reason why a dialog is shown is somewhat fucked ...

Rails, callbacks, workers, and the race you never expected to lose « Logical Friday

How delayed jobs can make your after_save callbacks execute before the record is saved.

MySQL: Can I speed up LIKE queries by adding an index?

For string columns, MySQL indexes the left side of a string. That means an index can speed a like query that has a wildcard on the right side:

SELECT * FROM foo WHERE field LIKE "bar%" # will be faster with an index

It can not speed up a query that has a variable left side:

SELECT * FROM foo WHERE field LIKE "%bar%" # will not be faster with an index

That also means if you use the ancestry gem you should index your ancestry column if you use scopes like descendants or `su...

RubyMine: Accessing views and partials from controllers

You can quickly access views that belong to a controller by using the tiny "page with arrow" icon in the gutter: icon

Access a method's view file

Click the icon next to the method definition in the controller.

If a view file does not yet exist, RubyMine will prompt you for its filename.

All views & partials associated to a controller

For a list of all views and partials that belong to the current ...

Mock the browser time or time zone in Selenium features

In Selenium features the server and client are running in separate processes. Therefore, when mocking time with a tool like Timecop, the browser controlled by Selenium will still see the unmocked system time.

timemachine.js allows you to mock the client's time by monkey-patching into Javascript core classes. We use timemachine.js in combination with the Timecop gem to synchronize the local browser time to the ...

Why stubbing on associated records does not always work as expected

Be careful when stubbing out attributes on records that are defined by associations. Nothing is as it seems to be.

The associated record has its own universe of things; when delegating calls to it, you ca not stub methods on the associated record and expect them to be around. That is a general issue with this pattern/approach.

What's happening?

Consider these classes:

class Post < ActiveRecord::Base
  belongs_to :thread
  
  def thread_title
    thread.title
  end
end

class Thread < Acti...

Git Landscaping

I recently worked on a project with 60+ old feature branches. Most of them had been merged into master and were subsequently abandoned. We decided we wanted to clean up a bit, and git made that easy.

Asset pipeline: Reasons why your stylesheet is empty

It might be one of the following:

  • You are looking at a manifest file (like application.css) which is always empty during development
  • Your Sass file has a syntax error it did not handle properly

Firebug tip: Log DOM Events

This Firebug feature is called simply Log Events and allows developers to log DOM events into the Console panel.

All you need to do is right click on an element in the HTML panel, pick Log Events from the context menu and switch to the Console panel to see the logs in action.

Test your CSS rendering output with GreenOnion

No one wants to cry over regression issues in views; does testing HTML and CSS have to be such a back and forth between designers and devs? Why is it that the rest of the stack can have TDD and BDD but not the presentation layer? Well, GreenOnion is here to help you get the same results on testing front-end styling that you've enjoyed in your unit and integration tests up to now.
GreenOnion records 'skins', which are snapshots of the current state of a view (or any page that a browser can navigate to). The first time that it is run on a view...

ReText

ReText is a cross-platform WYSIWYG-ish Markdown editor.

Toggle editor and preview layout with Ctrl+E.\
Press Ctrl+L to split the window for a live preview.

I use it to copy Pivotal Tracker story descriptions over, switch to the preview and have it as a small always-on-top window in a corner of one of my screens.


On Ubuntu, you can use a PPA to install:

sudo add-apt-repository ppa:mitya57/ppa
sudo apt-get update
sudo apt-get install retext

Twitter Bootstrap: Base CSS

Explanation of the "bootstrap 2" base CSS.

Contains information about:

  • Typography
  • Code
  • Tables
  • Forms
  • Buttons
  • Icons

jQuery 1.8 Released

No big features, but many improvements under the hood:

  • Faster selector engine
  • Many bug fixes

Note that jQuery 2.0, scheduled for early 2013, will remove support for IE6 and 7. Before that there will be one more minor release with 1.9 that still has support for ancient IEs.

Silencing Your Staging Environment - The Hashrocket Blog

Testing with real live production data does come with at least one catch. All those real live users in your production environment have real live email addresses that receive real live emails.

The post includes monkey patch for ActionMailer that rewrites the domain of all recipients. It's a different take on the problem than our own mail_magnet gem.