browsermedia / browsercms

BrowserCMS: Humane Content Management for Rails
http://browsercms.org
GNU Lesser General Public License v3.0
1.17k stars 260 forks source link

BrowserCMS can't access regular rails routes from inside template/partial #740

Closed neilabdev closed 9 years ago

neilabdev commented 9 years ago

Not sure if this is a bug, but what I am experiencing is the inability to use a route defined in the routes.rb file from inside a partial or template accessed via the CMS (as apposed to directly to my controller which may access the same view). Perhaps the context in which the partial is executing is not the same as it would be for a normal view, thus can't find the route, as the necessary helpers may not be included? Not sure. Nevertheless, if this is the case, access would be helpful long term, but would settle for a means to access routes from in such a view that would also work outside BrowserCMS so the reference is uniform.

Message
undefined local variable or method `report_search_path' for #<#<Class:0x007f9232613638>:0x007f9232615f78>
Stacktrace
/path/to/rails_root/app/views/shared/_header.html.erb:11:in `_app_views_shared__header_html_erb___388261459390954190_70132899426740'
/

Here is my routes:

My::Application.routes.draw do

  namespace :cms do
    content_blocks :regions
  end

  #root :to => 'sites#index'
  devise_for :users, :controllers =>
      ActiveAdmin::Devise.config.merge({
        :sessions => "sessions",
        :passwords => "passwords",
        :unlock => "unlocks",
        :registrations => "registrations"
      })

  devise_scope :user do
    delete "/users/sign_out", :to => "sessions#destroy"
    post "/users/sign_out", :to => "sessions#destroy"
    get "/users/sign_out", :to => "sessions#destroy"

  end

  match '/cms/dashboard', to: 'cms/dashboard#index', as: 'cms_dashboard'
  match '/report' => 'reports#index', :as => :report_index
  match '/report/search' => 'reports#search', :as => :report_search
  match '/report/:slug' => 'reports#summary', :as => :report_summary
  match '/report/download/:id' => 'reports#download', :as => :report_download

  ActiveAdmin.routes(self)
  mount_browsercms
end
peakpg commented 9 years ago

Due to how engines work, its sometimes not clear which Engine a view believes its in. Try adjusting the route calls in your partial to this:

main_app.report_search_path

On Tue, Sep 23, 2014 at 2:22 PM, valerius notifications@github.com wrote:

Not sure if this is a bug, but what I am experiencing is the inability to use a route defined in the routes.rb file from inside a partial or template accessed via the CMS (as apposed to directly to my controller which may access the same view). Perhaps the context in which the partial is executing is not the same as it would be for a normal view, thus can't find the route, as the necessary helpers may not be included? Not sure. Nevertheless, if this is the case, access would be helpful long term, but would settle for a means to access routes from in such a view that would also work outside BrowserCMS so the reference is uniform.

Message undefined local variable or method report_search_path' for #<#<Class:0x007f9232613638>:0x007f9232615f78> Stacktrace /path/to/rails_root/app/views/shared/_header.html.erb:11:in_app_views_shared__header_html_erb___388261459390954190_70132899426740' /

Here is my routes:

My::Application.routes.draw do

namespace :cms do content_blocks :regions end

root :to => 'sites#index'

devise_for :users, :controllers => ActiveAdmin::Devise.config.merge({ :sessions => "sessions", :passwords => "passwords", :unlock => "unlocks", :registrations => "registrations" })

devise_scope :user do delete "/users/sign_out", :to => "sessions#destroy" post "/users/sign_out", :to => "sessions#destroy" get "/users/sign_out", :to => "sessions#destroy"

end

match '/cms/dashboard', to: 'cms/dashboard#index', as: 'cms_dashboard' match '/report' => 'reports#index', :as => :report_index match '/report/search' => 'reports#search', :as => :report_search match '/report/:slug' => 'reports#summary', :as => :report_summary match '/report/download/:id' => 'reports#download', :as => :report_download

ActiveAdmin.routes(self) mount_browsercmsend

— Reply to this email directly or view it on GitHub https://github.com/browsermedia/browsercms/issues/740.

neilabdev commented 9 years ago

Thanks so much! That worked perfectly :)