ユーザーのフォロー/フォロー解除ボタンと同様に、ユーザーが作成したイベントに参加/参加解除ボタンを追加しようとしています。
@rsvps を event#show のように定義する方法がわかりません
イベントの NameError#show #<#:0x007f9dfaf9d978> の未定義のローカル変数またはメソッド「イベント」
show.html.erb
<%= link_to "Join Event", rsvps_path(:event_id => event), :method => :post %>
events_controller.rb
def show
@event = Event.find(params[:id])
@user = current_user
#@rsvp = ???? something here ????
end
rsvps_controller.rb
class RsvpsController < ApplicationController
before_filter :signed_in_user
def create
@rsvp = current_user.rsvps.build(:event_id => params[:event_id])
if @rsvp.save
flash[:notice] = "Joined event."
redirect_to root_url
else
flash[:error] = "Unable to join event."
redirect_to root_url
end
end
def destroy
@rsvp = current_user.rsvps.find(params[:id])
@rsvp.destroy
flash[:notice] = "Unjoin Event."
redirect_to current_user
end
end
モデルはこちら
rsvp.rb
class Rsvp < ActiveRecord::Base
attr_accessible :event_id, :user_id
belongs_to :user
belongs_to :event
end
user.rb
has_many :rsvps
has_many :events, through: :rsvps, dependent: :destroy
event.rb
belongs_to :user
has_many :rsvps
has_many :users, through: :rsvps, dependent: :destroy