Skip to content

Instantly share code, notes, and snippets.

@robyurkowski
Created November 9, 2010 06:03
Show Gist options
  • Save robyurkowski/668773 to your computer and use it in GitHub Desktop.
Save robyurkowski/668773 to your computer and use it in GitHub Desktop.
Weird routing error.
<%= form_tag('/posts/results/', {:id => 'search_form'}) do -%>
<%= text_field_tag :search, nil, {:style => 'display: none;', :id => 'search_field' } -%>
<%- end -%>
<h2>Routing Error</h2>
<p>No route matches "/posts/results"</p>
class Post < ActiveRecord::Base
scope :published, lambda {|val| where(:published => (val == true ? true : false)).order("created_at DESC") }
end
class PostsController < ApplicationController
def results
params[:search] = params[:search].blank? ? '%' : "%#{params[:search]}%"
@posts = Post.where("body LIKE ? OR title LIKE ?", params[:search], params[:search]).published(true).paginate(:per_page => 5, :page => params[:page])
render :action => :index
end
end
Blog::Application.routes.draw do
resources :posts do
collection do
get :results
get :drafts
end
resources :comments do
post 'disemvowel', :on => :member
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment