【问题标题】:Complaints that a route is missing while it's not抱怨一条路线丢失而它不是
【发布时间】:2013-01-26 00:12:12
【问题描述】:

我正在开发一个非常简单的项目管理网络应用程序。

我有两个不同的页面供您查看项目。

1. View all projects
2. View only the projects where you are administrator (includes buttons for editing / deletion of the projects)

因为我有两个不同的页面来显示项目,所以我决定创建一个自定义路由,将用户引导到项目控制器中的自定义操作。

但是,这(由于某种原因)不起作用,并且我收到以下错误消息:

No route matches {:action=>"edit", :controller=>"projects"}

观点:

<%= link_to "Manage projects", users_projects_path %>

项目负责人:

class ProjectsController < ApplicationController
    ...
    def users_projects
      @users_projects = Project.where(:user_id => current_user.id)
    end
...
end

项目模型:

class Project < ActiveRecord::Base
  has_and_belongs_to_many :users, :class_name => 'User'

  belongs_to :user
  has_many :tickets, :dependent => :destroy

  //validation

  attr_accessible :user_id, :title, :description, :start_date, :end_date
end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 model controller routes


    【解决方案1】:

    问题是您没有为路由提供id 参数,这是必需的。

    在某处,您正在生成指向edit_project_path 的链接。确保您将项目提供给该 url 生成器:edit_project_path(project)

    【讨论】:

    • +1,因为我是一个了不起的 Android 人......哦,答案。那也很好。 :)
    • 好的,但在这种情况下,我想将用户重定向到包含所有项目(用户拥有)的页面,而不是特定项目。怎么可能做到?
    • 当您显示链接或有人单击它时是否会出现错误消息?我的猜测是它是在有人点击它之后,因此它是显示所有引发错误的配置文件的页面。如果您显示您的路线文件和完整的错误跟踪消息可能会有所帮助。
    猜你喜欢
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 2023-02-14
    • 1970-01-01
    相关资源
    最近更新 更多