0

Devise cancan ブートストラップリポジトリの上に構築された Rails アプリケーションがあります。

ログインとアカウントのすべての機能を備えているので、管理者 (アカウント権限の変更)、マネージャー (従業員の時間を承認してプロジェクトを作成)、および従業員 (時間を記録し、現在取り組んでいるプロジェクトを確認) を使用できます。

私がやろうとしているのは、従業員が時間を記録するためのページを作成することです。足場をセットアップし、その足場のフォームを含むビューを生成しますが、私の質問は、ナビゲーションからそのページにリンクする方法と、ログに記録された時間がその特定の従業員に関連付けられるようにする方法です。 .

私の足場は

rails g scaffold hours email:string day:date hours:integer
4

1 に答える 1

0

Assuming that you've declared the belongs_to and has_many relationships in the models, and that the hours model includes the user_id foreign key (t.references :users in the migration), and that the relationship from user to hours is called hours, then you'd use something very close to this:

current_user.hours.create(params)

It starts with the current_user and traverses the assocoiation, which causes the user_id to be set in the User record when you call create. current_user is the Devise method for access to the User object for whomever Devise thinks is logged in.

于 2013-06-11T21:15:47.437 に答える