Supported route prefix (or namespace) which was added in Rails 3.1. #322

Open
wants to merge 3 commits into
from
@harai

Supported mountable engine's route prefix (or namespace), which was added in Rails 3.1.

Refinery CMS 2, the most popular cms which supports Rails 3.2, requires this feature because it has highly modularized design and it is common to refer to other engine's url from view.

@yuki24
Collaborator

The option is reasonable, but we can't merge this Pull Request for now since we have tons of issues about url_for. And I have some commends:

I keep this PR open and will possibly consider this again after we solve other url_for/routing issues.

@harai

Some specs failed on Travis: https://travis-ci.org/yuki24/kaminari/builds/3659060

This is because the method my_engine in the specs is not defined on Sinatra. This is not really a problem when using it on Sinatra, but the failure must be fixed somehow.

The name route_prefix implies that it is a String object, but it is an ActionDispatch::Routing::RoutesProxy object.

That might be the most difficult problem on this issue. As you say, the naming is not good. But I could not find a better name. will_paginate had the same issue before, and they decided to use scope. But in Kaminari, the word scope has been already used for other purpose. We have to find another name.

Does anyone have a good idea?

@harai

I have fixed the both issues.
I don't know if the name route_set is the best, but at least it is better than the previous name.

@jcoyne

@yuki24 Can you take another look at merging this pull request? I'm still having this trouble.

@mjacobus

I have a crud controller that extends MyEngine::Base controller. The view there is scoped to 'my_engine'. I know that because "main_app.customer_path(customer)" works and "customer_path(customer)" does not.

So, I am in the "my_route" context, and I would like to paginate using helpers of my main app. But the examples bellow wont work.

 # wont work: ActionController::RoutingError
<%= paginate(@customers, params: { route_set: :main_app }) %>

 # undefined method paginate (but I can use pagination in the main app
 # when it does not extend MyEngine controller)
<%= main_app.paginate(@customers) %>

So, I am also looking forward to that pull request being merged :)

Excelent job guys. Great plugin.

@dalpo

Great job! I'm waiting for the merge too =)

@jcoyne

@yuki24 Any update?

@dchandekstark

+1. Fixes my problem. Thanks!

@RonnieOnRails

Up @yuki24. This PR is really wanted. Thank you.

@jackkinsella

+1 Necessary for another major modular Rails open source application, Spree

@yuki24 yuki24 was assigned Jul 18, 2013
@zzak
Collaborator

@jackkinsella Does Spree maintain 3.1? I'm not sure that we do.

@jackkinsella

@zzak - I'm not sure what you mean by the question. I'm using a relatively recent 1.3X version of Spree with Rails 3.2.X.

@jcoyne

This is issue is also a problem with Rails 4. This patch is direly needed. As no action has been taken for 6 months, I'm considering forking and releasing a new version of this gem with this patch.

@zzak
Collaborator

@jackkinsella I must have confused since with before.

@zzak
Collaborator

Sorry but I must hold off on this until next version, we are working on url_for as @yuki24 mentioned.

@eitoball

ping @zzak @yuki24

Can we merge this PR then work on issues on url_for?
We should release new version. The last release (0.14.1) was one year ago 😨

@neversion neversion referenced this pull request in projecthydra-deprecated/curate Oct 18, 2013
Closed

Can't work with rails 4.0? #211

@zzak
Collaborator
@jcoyne

@zzak Any update on what needs to be done? I've been using this fork/branch for 10 months, In production for 6. It's a really important feature for me.

@cam156

+1 merge please

@villins

+1 merge please

@yuki24 yuki24 modified the milestone: 1.0.0 Apr 1, 2014
@mutley

@zzak @yuki24 First thank you for your hard work on this gem. Why has no action been taken on this it seems to be a very large issue spanning at least 4 duplicate issues from what I can see.

@yuki24 yuki24 referenced this pull request Jul 20, 2014
Closed

Add url_helper option #577

@zzak
Collaborator

Since master is at alpha should we commit new feature requests?

@bmaddy

+1 merge please--I just lost a few hours trying to figure this out also.

@ybian

+1

@jparr jparr referenced this pull request in projecthydra/sufia Oct 4, 2014
Closed

ActionController::UrlGenerationError in My::Files#index #674

@jcoyne jcoyne added a commit to jcoyne/kaminari that referenced this pull request Dec 23, 2014
@jcoyne jcoyne Support for rails engines route prefix
This is merging the work on harai:route_prefix_prototype in PR #322
5d1bee6
@parndt

I have this in config/initializers/kaminari_monkey_patch.rb

# Please see https://github.com/amatsuda/kaminari/pull/322 for an explanation.
# This fixes an issue when using Kaminari with engines/main_app.

Rails.application.config.to_prepare do
  Kaminari::Helpers::Tag.class_eval do
    def page_url_for(page)
      arguments = @params.merge(@param_name => (page <= 1 ? nil : page), :only_path => true)
      begin
        @template.url_for arguments
      rescue
        @template.main_app.url_for arguments
      end
    end
  end
end

Inelegant, as it requires knowledge of the internals, but a seemingly stable workaround.

@francirp

@parndt thanks...I slightly modified your solution and it worked for me:

In my Rails Engine at lib/kaminari/helpers/tag.rb:

module Kaminari
  module Helpers
    class Tag

      def page_url_for(page)
        arguments = @params.merge(@param_name => (page <= 1 ? nil : page), :only_path => true).symbolize_keys
        begin
          MyEngineName::Engine.routes.url_helpers.url_for arguments
        rescue
          @template.main_app.url_for arguments
        end
      end

    end
  end
end

Make sure to require the file at lib/your_engine.rb with require "kaminari/helpers/tag"

@spr7b

+1 Merge please. This is costing many hours of developer time!

@yuki24
Collaborator

I was looking into Rails to figure out what we can do about this. Does _with_routes helper method work?

<% _with_routes routes_proxy do %>
  <%= paginate @comments %>
<% end %>

I know it seems like a private API but I would prefer this rather than changing kaminari. I can also send a pull request to Rails to make _with_routes a public API. WDYT?

@jcoyne jcoyne added a commit to jcoyne/kaminari that referenced this pull request Feb 16, 2015
@jcoyne jcoyne Support for rails engines route prefix
This is a rebase of the work done by @harai in PR #322
0799f31
@grosscol

Is this merge request going to age out or be decided upon?

@nicusg nicusg added a commit to nicusg/kaminari that referenced this pull request Jun 17, 2015
@jcoyne jcoyne Support for rails engines route prefix
This is a rebase of the work done by @harai in PR #322
242b998
@seancdavis seancdavis referenced this pull request in seancdavis/cambium Jun 25, 2015
@seancdavis seancdavis monkeypatch for inhouse 3754aca
@archSeer archSeer added a commit to Boomkat/kaminari that referenced this pull request Sep 17, 2015
@archSeer archSeer Extract the page_url_for patch from #322. e592698
@archSeer archSeer added a commit to Boomkat/kaminari that referenced this pull request Sep 17, 2015
@archSeer archSeer Extract the page_url_for patch from #322. 6c9591f
@mjgiarlo mjgiarlo referenced this pull request in cbeer/kaminari_route_prefix Mar 9, 2016
Open

Post link to this gem in Kaminari megathread #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment