Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails routing url name helpers

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?

like image 659
mabounassif Avatar asked Feb 23 '23 06:02

mabounassif


2 Answers

Had to use main_app.new_refinery_news_url instead.

like image 140
mabounassif Avatar answered Mar 04 '23 14:03

mabounassif


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"}
like image 42
miaout17 Avatar answered Mar 04 '23 12:03

miaout17