私はRailsを使い始めています。私は、ユーザプロファイルがジョブに適用できるアプリケーションを構築しています。私は関連を通してhas_manyを作成しました。しかし、コントローラとビューを定義する方法は見つけられません。ここに私のコードは次のとおりです。Has_many through association - 表示しますか?コントローラ?
モデル:
class Profile < ActiveRecord::Base
has_attached_file :profileimg, :default_url => ":style/profile-img.jpg"
validates_attachment_content_type :profileimg, content_type: /\Aimage\/.*\Z/
belongs_to :user
has_many :relationships
has_many :jobs, through: :relationships
end
class Job < ActiveRecord::Base
belongs_to :employer
has_many :relationships, dependent: :destroy
has_many :profiles, through: :relationships
end
class Relationship < ActiveRecord::Base
belongs_to :profile
belongs_to :job
end
PS:私は、Railsのコンソール上の関係を作成することができ、それが動作します。
RelationshipsControllerを書くにはどうすればよいですか? current_user.profileがそのジョブに適用できるボタンを私のJobページにどのように置くのですか?
ありがとう!!ええ、プロフィールとユーザーはあなたが提案した関係を持っている、私はちょうど質問にそれらを書いていない。私はこれを試してみましょう:) –
ルートにルートを追加すると、「間違った引数(与えられた1、期待された0)」が返されます。 –
ああ、私の構文エラーでした。 。 – Deep