Refactored duplicate logic to a before_filter. #1914
This commit is contained in:
1 parent
86c1990faa
commit
2fe0bd3052
1 file changed
+23
-27
@@ -1,25 +1,16 @@
|
|||||||
class RatesController < ApplicationController
|
class RatesController < ApplicationController
|
||||||
helper :users
|
helper :users
|
||||||
before_filter :require_admin
|
before_filter :require_admin
|
||||||
|
before_filter :require_user_id, :only => [:index, :new]
|
||||||
|
|
||||||
# GET /rates?user_id=1
|
# GET /rates?user_id=1
|
||||||
# GET /rates.xml?user_id=1
|
# GET /rates.xml?user_id=1
|
||||||
def index
|
def index
|
||||||
begin
|
@rates = Rate.history_for_user(@user)
|
||||||
@user = User.find(params[:user_id])
|
|
||||||
@rates = Rate.history_for_user(@user)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.xml { render :xml => @rates }
|
format.xml { render :xml => @rates }
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
respond_to do |format|
|
|
||||||
flash[:error] = l(:rate_error_user_not_found)
|
|
||||||
format.html { redirect_to(home_url) }
|
|
||||||
format.xml { render :xml => "User not found", :status => :not_found }
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,20 +28,11 @@ class RatesController < ApplicationController
|
|||||||
# GET /rates/new?user_id=1
|
# GET /rates/new?user_id=1
|
||||||
# GET /rates/new.xml?user_id=1
|
# GET /rates/new.xml?user_id=1
|
||||||
def new
|
def new
|
||||||
begin
|
@rate = Rate.new(:user_id => @user.id)
|
||||||
@user = User.find(params[:user_id])
|
|
||||||
@rate = Rate.new(:user_id => @user.id)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.xml { render :xml => @rate }
|
format.xml { render :xml => @rate }
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
|
||||||
respond_to do |format|
|
|
||||||
flash[:error] = l(:rate_error_user_not_found)
|
|
||||||
format.html { redirect_to(home_url) }
|
|
||||||
format.xml { render :xml => "User not found", :status => :not_found }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -104,4 +86,18 @@ class RatesController < ApplicationController
|
|||||||
format.xml { head :ok }
|
format.xml { head :ok }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def require_user_id
|
||||||
|
begin
|
||||||
|
@user = User.find(params[:user_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
respond_to do |format|
|
||||||
|
flash[:error] = l(:rate_error_user_not_found)
|
||||||
|
format.html { redirect_to(home_url) }
|
||||||
|
format.xml { render :xml => "User not found", :status => :not_found }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user