没有路线匹配[GET]“/ account / undefined”

时间:2014-01-12 13:27:12

标签: ruby-on-rails ruby ruby-on-rails-4

在我的rails应用程序中,我的路径文件中有一个命名空间,

namespace :account do
  resources :activities       
end

我的控制器是

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

在我的索引视图中,我试图通过这样做来访问节目页面:

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

当我正在运行rake路线时,我得到了这个结果:

  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

当我直接点击localhost:3000:/ account / activities / 1时,我会转到正确的页面,但是当我点击索引视图中的show链接时,我收到此错误:< / p>

没有路线匹配[GET]“/ account / undefined”

我正在使用rails 4,直到今天一切正常。我不知道发生了什么,所以如果你有任何想法,可能会很棒

非常感谢

1 个答案:

答案 0 :(得分:1)

对于任何偶然发现此问题的人,希望这会有所帮助。检查你的javascript事件!

我在两个HTML页面之间有一个共享的JS文件。两个不同的人正在处理每个页面,并且两个人都将CHANGE事件处理程序附加到元素ID。

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

两个事件都在每个页面上执行,导致UNDEFINED路径。