Closed steveraden closed 7 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.]
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.
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?
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
I have tried a few more things but I am flailing in the dark....
@sturad What do you really want to do?
@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!
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.)
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.
@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.
@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/).
@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!
@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.
Could i close this issue ?
@bricesanchez when #3146 is merged
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
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
and this decorator #app/decorators/controllers/refinery/pages/pages_controller_decorator.rb
I get this error when starting Rails.
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
Gemfile lock follows: