4

What basic settings are required to make sure routing url name helpers work?

For instance in my route I have the following:

Blog::Application.routes.draw do
  resources :news, :as => :news_items, :controller => :news_items, :only => [:show, :index]

  scope :module => "refinery" do
    scope(:path => 'refinery', :as => 'admin', :module => 'Admin') do
      resources :news, :except => :show, :as => :news_items, :controller => :news_items
    end
  end
end

but the following doesn't seem to work:

new_refinery_news_url

I keep on getting the error

undefined local variable or method `new_refinery_news_url'

So I'm pretty sure something is missing in the way I have configured my application, who's main routing is in the RefineryCMS gem which was added in the Gemfile.

Any thoughts?

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
mabounassif
  • 2,311
  • 6
  • 29
  • 46

4 Answers4

5

Had to use main_app.new_refinery_news_url instead.

mabounassif
  • 2,311
  • 6
  • 29
  • 46
2

The helper name will be new_admin_news_item_url.

It's simple to find all routes and their helper methods. Just run rake routes and you will see:

          news_items GET    /news(.:format)                   {:action=>"index", :controller=>"news_items"}
           news_item GET    /news/:id(.:format)               {:action=>"show", :controller=>"news_items"}
    admin_news_items GET    /refinery/news(.:format)          {:action=>"index", :controller=>"refinery/Admin/news_items"}
                     POST   /refinery/news(.:format)          {:action=>"create", :controller=>"refinery/Admin/news_items"}
 new_admin_news_item GET    /refinery/news/new(.:format)      {:action=>"new", :controller=>"refinery/Admin/news_items"}
edit_admin_news_item GET    /refinery/news/:id/edit(.:format) {:action=>"edit", :controller=>"refinery/Admin/news_items"}
     admin_news_item PUT    /refinery/news/:id(.:format)      {:action=>"update", :controller=>"refinery/Admin/news_items"}
                     DELETE /refinery/news/:id(.:format)      {:action=>"destroy", :controller=>"refinery/Admin/news_items"}
miaout17
  • 4,715
  • 2
  • 26
  • 32
  • That's the thing, all the routes from `rake routes` are not working. The only way to bypass this problem is by directly using '/refinery/news/new' like so `<%= link_to t('.create'), '/refinery/news/new' , :class => "add_icon" %>` – mabounassif Nov 30 '11 at 05:15
1

With mountable engines you always need to specify "main_app." (or for Refinery routes "refinery.") prefix because engines are isolated from the application.

foomip
  • 574
  • 7
  • 7
0

A solution, if you're using routes outside of refinery, is to prefix the named_path with the Rails object that contains the methods for named routes

Rails.application.routes.url_helpers.new_admin_news_item_path
New Alexandria
  • 6,951
  • 4
  • 57
  • 77