picardo
picardo

Reputation: 24886

Using Rails Url Helper

I have a search form in the header of my site, such as this:

=semantic_form_for :search, :url=>{:controller=>:listings,:action=>:search} do
...

This works fine except when the controller for the current page is scoped or namespaced -- not sure which. For example, '/users/sign_in' page is controlled by Devise and its controller is inside Devise namespace.

On that page, I get an error message that indicates that the action does not exist under Devise::Listings controller. (Of course it does not, because Listings controller is not in the Devise namespace.)

How do I make sure that url helper does not automatically prefix the namespace of the controller for the current page?

Upvotes: 0

Views: 642

Answers (1)

Bryan Drewery
Bryan Drewery

Reputation: 2636

Try using a named route.

config/routes.rb

controller 'listings' do
  get 'search', :as => :listings_search
end

View

=semantic_form_for :search, :url => listings_search_path do

Upvotes: 2

Related Questions