Skip to content

Instantly share code, notes, and snippets.

@ppworks
Created July 24, 2013 14:40
Show Gist options
  • Save ppworks/6071196 to your computer and use it in GitHub Desktop.
Save ppworks/6071196 to your computer and use it in GitHub Desktop.
ログインしてないときにアクセスした画面に戻りたい、GET以外でも。 ref: http://qiita.com/ppworks/items/f68f68a343fc88a76ad4
devise :users
resources :events do
resource :attendances, only: [:create, :destroy] # 参加処理
end
class EventsController < ApplicationController
before_action :authenticate_user!, only: [:new] # rails3 以下なら before_filter
def show
# イベント表示処理
end
def new
# イベント作成準備処理
end
end
class AttendancesController < ApplicationController
before_action :set_event
before_action :authenticate_user! # rails3 以下なら before_filter
def create
# イベント参加処理
end
def destroy
# イベント参加キャンセル処理
end
private
def store_event_url
session[:user_return_to] = event_path(@event)
end
end
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
class AttendancesController < ApplicationController
before_action :set_event
before_action :store_event_url # 追加!
before_action :authenticate_user! # rails3 以下なら before_filter
def create
# イベント参加処理
end
def destroy
# イベント参加キャンセル処理
end
private
# 追加!
def set_event
@event = Event.find(params[:event_id])
end
def store_event_url
session[:user_return_to] = event_path(@event)
end
end
= link_to(event_attendances_path(@event), method: :post, class: 'btn') do
= t('nav.attendaces.create')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment