actmd/abraham

How to handle controllers with the same name?

marwann opened this issue · 6 comments

Hi there,

Thanks for making Abraham :)

My issue is that I have some namespaced controllers / actions with the same name, eg. :

  • User::Dashboard#index
  • Admin::Dashboard#index

Namespaces aren't taken into account in Abraham so I had put my yml file inside tours/dashboard/index.en.yml which results in the tour displaying in both dashboards.

I've tried changing the initializer to take subfolders like tours/admin/dashboard/index.en.yml into account but with no luck, Abraham doesn't recognize the controller.

Any clue?

Thanks

This could probably done fairly easily by referring to controller_path instead of controller_name when making the Ajax call:

  tour.on("complete", function() {
    // ajax
    return $.ajax({
      url: "/abraham_histories/",
      type: "POST",
      dataType: "json",
      contentType: "application/json",
      data: JSON.stringify({
        authenticity_token: '<%= form_authenticity_token %>',
        controller_name: '<%= controller_name %>',
        action_name: '<%= action_name %>',
        tour_name: '<%= tour_name %>'
      })
    });

Supporting changes would be needed in the controller and database table.

http://api.rubyonrails.org/classes/AbstractController/Base.html#method-i-controller_path

Hi, @marwann! Thanks for your question and apologies for the frustration! We obviously didn't anticipate namespaces :(

I like @seanfcarroll's controller_path idea, though we'd have to figure out backward compatibility.

If we simple changed the code to use controller_path, applications that had already been using Abraham would suddenly see all their old tours reappear ;)

@seanfcarroll We actually discussed this topic among our team this morning, we're going to test your solution out here and try to get it included ASAP ;)

@jabbett glad it was helpful!

The tricky part was rewriting the initializer to load the yaml files while retaining the controller path. But now that I've figured that out, I expect to get this tested and released today.

@jabbett, @seanfcarroll - Thanks for making this a reality. I'll update Abraham in the next few days :)