问我如何使用ID ni my URI模式过滤我的get api函数 例如,如果客户端使用localhost:3000 / users / 1 / projects 他将获得一个" user_id"等于URI模式/ users /:id
#routes 资源:用户做的 资源者:项目 端
#project controller
def index
@projects = Project.all
render json: @projects
end
#users assocciation
has_many :projects, dependent: :destroy
has_many :tasks, dependent: :destroy
has_many :comments, dependent: :destroy
#project association
class Project < ActiveRecord::Base
has_many :task, dependent: :destroy
belongs_to :user
end
#DB schema
create_table "projects", force: :cascade do |t|
t.string "name"
t.text "descriptions"
t.date "startDate"
t.date "dueDate"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.boolean "project_confirmation"
端
我们想要的是当客户端使用此路由/users/:user_id/projects(.:format)时,他接受的项目的user_id字段类似于routes / users /:id
答案 0 :(得分:0)