refinery / refinerycms

An extendable Ruby on Rails CMS that supports Rails 6.0+
https://www.refinerycms.com/
MIT License
3.9k stars 1.26k forks source link

Issues with creating a custom action as described in guide #3119

Closed steveraden closed 7 years ago

steveraden commented 8 years ago

I am having difficult in creating a custom action as described in 4.3 of creating a custom action here http://www.refinerycms.com/guides/using-custom-view-or-layout-templates. I’m using Refinery 3.0.1and Rails 4.2.4, Ruby ruby-2.2.0. I create sample project just to retest this issue: (https://github.com/sturad/refinery_custom_action_issue/)

Rails doesn't start with a custom action defined by this routes.rb

Refinery::Core::Engine.routes.prepend do
  get '/about-us', :to => 'pages#about_us', :as => :about_us
end
Rails.application.routes.draw do
  mount Refinery::Core::Engine, at: Refinery::Core.mounted_path
end

and this decorator #app/decorators/controllers/refinery/pages/pages_controller_decorator.rb

Refinery::PagesController.class_eval do
   skip_before_action :find_page, :only => [:about_us]
  def about_us
    # hardcoded id to debug query success
    @page = ::Refinery::Page.find(1)
    byebug
    render_with_templates?
  end
end

I get this error when starting Rails.

/Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route': Invalid route name, already in use: 'about_us'  (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1561:in `add_route'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1536:in `decomposed_match'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1517:in `block in match'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1507:in `each'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:1507:in `match'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:689:in `map_method'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:650:in `get'
  from /Users/sraden/code/test_cms/refinery4/config/routes.rb:2:in `block in <top (required)>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:601:in `instance_exec'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:601:in `block in with_default_scope'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:816:in `scope'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/mapper.rb:600:in `with_default_scope'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:450:in `block in clear!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:450:in `each'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:450:in `clear!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/routing-filter-0.5.1/lib/routing_filter/adapters/rails.rb:37:in `clear_with_filtering!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:35:in `block in clear!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:33:in `each'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:33:in `clear!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:15:in `reload!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/refinerycms-pages-3.0.1/lib/refinery/pages/engine.rb:52:in `append_marketable_routes'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/refinerycms-pages-3.0.1/lib/refinery/pages/engine.rb:29:in `block in <class:Engine>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `run'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/initializable.rb:55:in `block in run_initializers'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `call'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
  from /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/initializable.rb:54:in `run_initializers'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/application.rb:352:in `initialize!'
  from /Users/sraden/code/test_cms/refinery4/config/environment.rb:5:in `<top (required)>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
  from /Users/sraden/code/test_cms/refinery4/config.ru:3:in `block in <main>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
  from /Users/sraden/code/test_cms/refinery4/config.ru:in `new'
  from /Users/sraden/code/test_cms/refinery4/config.ru:in `<main>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/server.rb:61:in `app'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/server.rb:139:in `log_to_stdout'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/server.rb:78:in `start'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
  from /Users/sraden/code/test_cms/refinery4/bin/rails:9:in `require'
  from /Users/sraden/code/test_cms/refinery4/bin/rails:9:in `<top (required)>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/client/rails.rb:28:in `load'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/client/rails.rb:28:in `call'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/client/command.rb:7:in `call'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/client.rb:28:in `run'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/bin/spring:49:in `<top (required)>'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/binstub.rb:11:in `load'
  from /Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/spring-1.6.3/lib/spring/binstub.rb:11:in `<top (required)>'
  from /Users/sraden/code/test_cms/refinery4/bin/spring:13:in `require'
  from /Users/sraden/code/test_cms/refinery4/bin/spring:13:in `<top (required)>'
  from bin/rails:3:in `load'
  from bin/rails:3:in `<main>'

When I remove the :as paremeter in the route, I can start Rails, but attempt to bypass normal PagesContoller.find_page() does not work. Debugging shows that find_page is called with action_name set to 'about' So my skip_before_action trigger is not firing

'NoMethodError (undefined method `live?' for false:FalseClass):
  refinerycms-pages (3.0.1) app/controllers/refinery/pages_controller.rb:63:in current_user_can_view_page?'
  activesupport (4.2.4) lib/active_support/callbacks.rb:432:in `block in make_lambda'
  activesupport (4.2.4) lib/active_support/callbacks.rb:417:in `call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:417:in `block in invert_lambda'
  activesupport (4.2.4) lib/active_support/callbacks.rb:144:in `call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:144:in `block (2 levels) in halting_and_conditional'
  activesupport (4.2.4) lib/active_support/callbacks.rb:144:in `each'
  activesupport (4.2.4) lib/active_support/callbacks.rb:144:in `all?'
  activesupport (4.2.4) lib/active_support/callbacks.rb:144:in `block in halting_and_conditional'
  activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `block in call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `each'
  activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
  activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
  activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.4) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.4) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.4) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.4) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `call'
  actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
  actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:45:in `serve'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
  railties (4.2.4) lib/rails/engine.rb:518:in `call'
  railties (4.2.4) lib/rails/railtie.rb:194:in `public_send'
  railties (4.2.4) lib/rails/railtie.rb:194:in `method_missing'
  actionpack (4.2.4) lib/action_dispatch/routing/mapper.rb:51:in `serve'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in `call'
  dragonfly (1.0.12) lib/dragonfly/middleware.rb:14:in `call'
  dragonfly (1.0.12) lib/dragonfly/middleware.rb:14:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  activerecord (4.2.4) lib/active_record/migration.rb:377:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  dragonfly (1.0.12) lib/dragonfly/cookie_monster.rb:9:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.4) lib/rails/engine.rb:518:in `call'
  railties (4.2.4) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /Users/sraden/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

Gemfile lock follows:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.4)
      actionview (= 4.2.4)
      activesupport (= 4.2.4)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.4)
      activesupport (= 4.2.4)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.4)
      activesupport (= 4.2.4)
      globalid (>= 0.3.0)
    activemodel (4.2.4)
      activesupport (= 4.2.4)
      builder (~> 3.1)
    activerecord (4.2.4)
      activemodel (= 4.2.4)
      activesupport (= 4.2.4)
      arel (~> 6.0)
    activesupport (4.2.4)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    acts_as_indexed (0.8.3)
    addressable (2.4.0)
    arel (6.0.3)
    awesome_nested_set (3.0.3)
      activerecord (>= 4.0.0, < 5)
    babosa (1.0.2)
    bcrypt (3.1.10)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    builder (3.2.2)
    byebug (8.2.2)
    coffee-rails (4.1.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.1.x)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.10.0)
    concurrent-ruby (1.0.0)
    debug_inspector (0.0.2)
    decorators (2.0.1)
      railties (>= 4.0.0, < 5.0.0)
    devise (3.5.6)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      responders
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    dragonfly (1.0.12)
      addressable (~> 2.3)
      multi_json (~> 1.0)
      rack (>= 1.3.0)
    erubis (2.7.0)
    execjs (2.6.0)
    friendly_id (5.1.0)
      activerecord (>= 4.0.0)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    globalize (5.0.1)
      activemodel (>= 4.2.0, < 4.3)
      activerecord (>= 4.2.0, < 4.3)
    i18n (0.7.0)
    jbuilder (2.4.1)
      activesupport (>= 3.0.0, < 5.1)
      multi_json (~> 1.2)
    jquery-rails (4.1.0)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (5.0.5)
      railties (>= 3.2.16)
    json (1.8.3)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    mime-types (2.99.1)
    mini_portile2 (2.0.0)
    minitest (5.8.4)
    multi_json (1.11.2)
    nokogiri (1.6.7.2)
      mini_portile2 (~> 2.0.0.rc2)
    orm_adapter (0.5.0)
    pg (0.18.4)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.4)
      actionmailer (= 4.2.4)
      actionpack (= 4.2.4)
      actionview (= 4.2.4)
      activejob (= 4.2.4)
      activemodel (= 4.2.4)
      activerecord (= 4.2.4)
      activesupport (= 4.2.4)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.4)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    rails-i18n (4.0.8)
      i18n (~> 0.7)
      railties (~> 4.0)
    railties (4.2.4)
      actionpack (= 4.2.4)
      activesupport (= 4.2.4)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.5.0)
    rdoc (4.2.2)
      json (~> 1.4)
    refinerycms (3.0.1)
      refinerycms-core (= 3.0.1)
      refinerycms-images (= 3.0.1)
      refinerycms-pages (= 3.0.1)
      refinerycms-resources (= 3.0.1)
    refinerycms-authentication-devise (1.0.4)
      actionmailer (~> 4.2, >= 4.2.0)
      devise (~> 3.0, >= 3.2.4)
      friendly_id (~> 5.1.0)
      refinerycms-core (~> 3.0, >= 3.0.0)
    refinerycms-core (3.0.1)
      actionpack (>= 4.2.3, < 5.0)
      activerecord (>= 4.2.3, < 5.0)
      awesome_nested_set (~> 3.0.0)
      coffee-rails (~> 4.0, >= 4.0.0)
      decorators (~> 2.0.0)
      jquery-rails (>= 2.3.0)
      jquery-ui-rails (~> 5.0.0)
      railties (>= 4.2.3, < 5.0)
      refinerycms-i18n (~> 3.0.0)
      sass-rails (>= 4.0, < 5.1)
      truncate_html (~> 0.9)
      will_paginate (~> 3.0.2)
      zilch-authorisation
    refinerycms-i18n (3.0.1)
      rails-i18n (~> 4.0.1)
      routing-filter (>= 0.4.0)
    refinerycms-images (3.0.1)
      dragonfly (~> 1.0.0)
      globalize (>= 4.0.0, < 5.2)
      refinerycms-core (= 3.0.1)
    refinerycms-pages (3.0.1)
      awesome_nested_set (~> 3.0.0)
      babosa (!= 0.3.6)
      friendly_id (~> 5.1.0)
      globalize (>= 4.0.0, < 5.2)
      refinerycms-core (= 3.0.1)
      seo_meta (~> 2.0.0.rc.1)
      speakingurl-rails (~> 8.0.0)
    refinerycms-resources (3.0.1)
      acts_as_indexed (~> 0.8.0)
      dragonfly (~> 1.0.0)
      globalize (>= 4.0.0, < 5.2)
      refinerycms-core (= 3.0.1)
    responders (2.1.1)
      railties (>= 4.2.0, < 5.1)
    routing-filter (0.5.1)
      actionpack (~> 4.2)
      activesupport (~> 4.2)
    sass (3.4.21)
    sass-rails (5.0.4)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sdoc (0.4.1)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    seo_meta (2.0.0.rc.1)
      railties (>= 3.0.0)
    speakingurl-rails (8.0.2)
      railties (>= 3.1)
    spring (1.6.3)
    sprockets (3.5.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.0.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (2.0.2)
    truncate_html (0.9.3)
    turbolinks (2.5.3)
      coffee-rails
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.2)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    warden (1.2.6)
      rack (>= 1.0)
    web-console (2.3.0)
      activemodel (>= 4.0)
      binding_of_caller (>= 0.7.2)
      railties (>= 4.0)
      sprockets-rails (>= 2.0, < 4.0)
    will_paginate (3.0.7)
    zilch-authorisation (0.0.1)

PLATFORMS
  ruby

DEPENDENCIES
  byebug
  coffee-rails (~> 4.1.0)
  jbuilder (~> 2.0)
  jquery-rails
  pg
  rails (= 4.2.4)
  refinerycms (~> 3.0.0)
  refinerycms-authentication-devise (~> 1.0)
  sass-rails (~> 5.0)
  sdoc (~> 0.4.0)
  spring
  turbolinks
  uglifier (>= 1.3.0)
anitagraham commented 8 years ago

Dumb question I know, but do you have two pages called 'about_us'? What does rake routes tell you (will it run?)? [I've never used this method, so am just looking at the problem from a general pov.]

steveraden commented 8 years ago

There is only only one Refinery::Page or page period is called about_us.

If I put in some debug output, you can see that there is some kind of circular calling between Rails.application.routes.draw.draw() and Refinery::Core::Engine.routes.prepend.prepend()

=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
draw
prepend
draw
prepend
Exiting
/Users/sraden/.rvm/gems/ruby-2.2.0@picbase/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route': Invalid route name, already in use: 'about_us'  (ArgumentError)

with the as clause removed, I see

draw
prepend
draw
prepend
prepend
draw

I'm not familiar with this kind of routing issue so I don't know if this circular calling is normally when booting Rails and using prepend. I also don't know if the patten in the guide (4.3) is valid for RefineryCMS stable.

anitagraham commented 8 years ago

I have tried this and get the same problem (even if I have no page called _aboutus).

Do we know who wrote this guide - they may be able to help better than I can?

anitagraham commented 8 years ago

I can get further with this process by disabling marketable_urls

Refinery::Pages.configure do |config|

  # Configure whether to enable marketable_urls
   config.marketable_urls = false
anitagraham commented 8 years ago

I have tried a few more things but I am flailing in the dark....

anitagraham commented 8 years ago

@sturad What do you really want to do?

steveraden commented 8 years ago

@anitagraham thanks for picking up on the issue. I really would like to build a hierarchical document page with a table of contents similar to this. So I want top level "pages' as headings", and then one to two levels of child "pages" or nodes/posts to render in the document. My idea was to use the Refinery::Page content type and then use the build-in child parent relationship in a controller decorator to pull the document tree which would render in a bespoke page template. This might be a relatively expensive operation and I only want to do it on one page so my thought was to have a custom action.

Another thing that I could use for this in other CMS is categories or taxonomy. I think there is an Refinery extension for that, but haven't looked at it too much.

My dumb question is that if I create an engine, do I get custom controller action and template anyway which might be better?

The simplest thing that work would be to have could having a single page body and drop the semantic markup into this field, but I wanted to checkout how I could do this a more CMS-like way.

Thanks!

anitagraham commented 8 years ago

No dumb questions: Yes, if you create an engine you get a controller etc all to yourself.

However, you may like to consider looking at menus and menu presenters. (but I have been working on menus/presenters myself, so I might have tunnel vision.)

steveraden commented 8 years ago

Thanks. I will look at both of these options. I think this issue should be left open while the guide is still mentioning the custom action pattern.

parndt commented 8 years ago

@sturad I've had a look at this and this can be solved with the following change:

-Refinery::Core::Engine.routes.prepend do
+Refinery::Core::Engine.routes.draw do
   get '/about-us', :to => 'pages#about_us', :as => :about_us
 end

The reason for this is that config/routes.rb gets loaded twice (at least) during Rails' boot process and using prepend doesn't take into account whether it has already been added, whereas draw seems to. I'm not sure what other impact this change has, but it lets it boot.

steveraden commented 8 years ago

@parndt Sorry late reply, not pursuing this issue actively. Your change to routes.rb makes a demo app bootable, but then I still do hit 'NoMethodError (undefined method `live?' for false:FalseClass). I updated this issue app to reflect: (https://github.com/sturad/refinery_custom_action_issue/).

parndt commented 8 years ago

@sturad can you please try this in your Gemfile:

gem "refinerycms", "~> 3.0.0", git: "https://github.com/refinery/refinerycms", branch: "feature/issue-3119"

This will allow you to define a method in your decorator:

def find_page_for_about_us
  @page = Refinery::Page.find_by(link_url: "/about-us") # or some other logic
end

It also addresses the assumption that we're even working with a page by preventing error_404 for custom actions.

I'm not sure if there are other implications yet, but we'll see on CI!

steveraden commented 8 years ago

@parndt That works with the modification When I tested this on that particular finder, I had to populate refinery_pages.link_url outside of the app. But I believe that was just some other error on my part setting up the page or at least #3146 seems nothing to do with that extra step.

bricesanchez commented 8 years ago

Could i close this issue ?

parndt commented 8 years ago

@bricesanchez when #3146 is merged

parndt commented 8 years ago

I've updated the code that you need to define now to:

class PagesController # this class exists
  module Finders
    class AboutUs
      def call(params)
        Refinery::Page.find_by(link_url: "/about-us") # or some other logic
      end
    end
  end
end

This is to avoid the metaprogramming of magic method names