Add RESTful Action

Posted by Drew Rush on Stack Overflow See other posts from Stack Overflow or by Drew Rush
Published on 2012-12-09T04:50:23Z Indexed on 2012/12/09 5:04 UTC
Read the original article Hit count: 208

Filed under:
|

The source of my information is section 2.9 here:

[http://guides.rubyonrails.org/routing.html#connecting-urls-to-code][1]

What I'm trying to do is add a custom action "search" and corresponding view.

So, as it says to do in the documentation, I've added this code in my config/routes.rb file:

  resources :dimensions do
  collection do
    get "search"
  end
  end

I've also defined in the dimensions_controller file:

  def search
    @dimensions = Dimension.all

    respond_to do |format|
      format.html # search.html.erb
      format.json { render json: @dimensions }
    end
  end

I then stopped and restarted the rails server, but when I navigate to /dimensions/home, I'm still getting this error message:

Couldn't find Dimension with id=search

Also showing that my parameter is:

{"id"=>"search"}

So am I just missing another bit of code that gives the instruction to interpret /dimension/search as a collection action as opposed to the show action?

Thanks for your time.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about routes