Created
July 24, 2013 14:40
-
-
Save ppworks/6071196 to your computer and use it in GitHub Desktop.
ログインしてないときにアクセスした画面に戻りたい、GET以外でも。 ref: http://qiita.com/ppworks/items/f68f68a343fc88a76ad4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devise :users | |
resources :events do | |
resource :attendances, only: [:create, :destroy] # 参加処理 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventsController < ApplicationController | |
before_action :authenticate_user!, only: [:new] # rails3 以下なら before_filter | |
def show | |
# イベント表示処理 | |
end | |
def new | |
# イベント作成準備処理 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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