私はprojectというモデルを持っていて、もう一つはinviteと呼ばれています。Rails 4 - 関連する外部キー値の設定
団体は以下のとおりです。
プロジェクト
has_many :invites
私はプロジェクトを作成し、ユーザーがプロジェクトに取り組んでそれらに参加する他のユーザーに招待状を送信できるようにしたい
belongs_to :project
招待します。私は、PROJECT_IDの値を設定しようとしている、上記のフォームで
<%= simple_form_for(@invite, :url => invites_path) do |f| %>
<%= f.hidden_field :recipient_id, :value => get_recipient_id %>
<%#= f.hidden_field :project_id, :value => current_user.profile.project_id %>
<%= f.hidden_field :project_id, :value => @invite.project_id %>
<%= f.label :email %>
<%= f.email_field :email %>
<!-- This field should use :date_picker- but it isnt working -->
<%= f.input :expiry, :as => :date, :label => "When do you need a response to this invitation?" %>
<%#= f.input :expiry, :as => :date_picker, :label => "When do you need a response to this invitation?" %>
<%= f.submit 'Send', :class=>"formsubmit" %>
<% end %>
:
は、私は次のように招待を作成するためのフォームを持っています。招待コントローラで
、私が持っている:私は、アクションの前にget_projectがプロジェクトになるだろうと思った
class InvitesController < ApplicationController
before_action :get_project
def index
@invites = @project.invites
end
def new
# @invite = Invite.new
@invite = @project.invites.build
end
def create
@invite = Invite.new(invite_params)
@invite.sender_id = current_user.profile.id
# @project = Project.find(params[:project_id])
if @invite.save
#send existing user email invitation to join project team
InviteMailer.existing_user_invite(@invite).deliver_later
format.html { redirect_to @project }
@invite.recipient.project.push(@invite.project)
else
@invite.recipient.project.push(@invite.project)
InviteMailer.new_user_invite(@invite, new_user_registration_path(:invite_token => @invite.token)).deliver
end
# oh no, creating an new invitation failed
end
private
# Use callbacks to share common setup or constraints between actions.
def set_invite
@invite = Invite.find(params[:id])
end
def get_project
@project = Project.find(params[:project_id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def invite_params
params[:invite].permit(:email, :project_id, :recipient_id)
end
end
。 PROJECT_IDのための私のフォームで隠しフィールドに
undefined method `project_id' for #<Profile:0x007fa179509b60>
Did you mean? project_ids
project_ids=
projects
object_id
エラーメッセージのポイント:代わりに、私はというエラーを取得します。
誰かが間違っているのを誰でも見ることができますか?
いいえ - 私は、エラーメッセージがコメントされていないこの行を指していると思います。<%= f.hidden_field:project_id、:value => @ invite.project_id%> – Mel
エラーメッセージはプロファイルについて何も言いません。これはproject_idのエラーについて話しています。 – Mel
'定義されていないメソッド' project_id for# 'エラーは、' profile'インスタンスに 'project_id'メソッドがないことを示しています。 –