0
votes

In my rails app, I have a namespace in my route file,

namespace :account do
  resources :activities       
end

My controller is

class Account::ActivitiesController < Account::AccountController

  before_action :find_activity, only: [:show, :edit]

  def index
    @activities = Activity.all
  end

  def show
  end

  private

  def find_activity
    @activity = Activity.find(params[:id])
  end

  def activity_params
    params.require(:activity).permit(:name, :description)
  end
end

In my index view I'n trying to access the show page by do this:

= @activities.each do |activity|
  = link_to "show", account_activity_path(activity)

When I'm running rake route, I get this result:

  account_activities GET    /account/activities(.:format)          account/activities#index
                      POST   /account/activities(.:format)          account/activities#create
 new_account_activity GET    /account/activities/new(.:format)      account/activities#new
edit_account_activity GET    /account/activities/:id/edit(.:format) account/activities#edit
     account_activity GET    /account/activities/:id(.:format)      account/activities#show
                      PATCH  /account/activities/:id(.:format)      account/activities#update
                      PUT    /account/activities/:id(.:format)      account/activities#update
                      DELETE /account/activities/:id(.:format)      account/activities#destroy

When I'm taping directly localhost:3000:/account/activities/1, I'm going to the right page, but when I click on the show link in my index view, I'm getting this error:

No route matches [GET] "/account/undefined"

I'm using rails 4, and everything worked fine until today. I don't see what's happen so if you have any ideas, could be great

Thanks a lot

1
Do you have a stack trace from the exception? My guess is that one of the links you're trying to render on the show page isn't what you think it is - Gareth
Perhaps try = link_to "show", account_activity_path(activity.id) ? - Richard Peck
Are you overriding to_params on Activity model or are you using any gem doing that (e.g. friendly_id)? - BroiSatse
Gareth: So you think my problem is on the show page? I'm getting this error even when I have nothing in my show.html.haml and my log in my show action didn't appear so I'm not sure it's going to the show action. RichPeck: I tried it but the result is the same. - maxencenoel
@BroiSatse: I'm not overriding my ID with to_param and I'm not using any gem for that. When I create the activity model and controller via scaffold everthing is ok but I have a namespace for the model like Account::Activity. I already did it with rails 3 without problems - maxencenoel

1 Answers

1
votes

For anyone else that stumbles upon this issue, hopefully this will help. Check your javascript events!

I had a shared JS file between two HTML pages. Two different people were working on each page and both people attached a CHANGE event handler to an element ID.

$("#site").change(function() {
    var url = $(this).data('url');
    window.location = url;
}

Both events were executing on each page, causing the UNDEFINED route.