22ec6f56b7
* Used in the User Administration panel so RatesController can redirect back to the panel as needed. #1914
115 lines
2.7 KiB
Ruby
115 lines
2.7 KiB
Ruby
class RatesController < ApplicationController
|
|
helper :users
|
|
before_filter :require_admin
|
|
before_filter :require_user_id, :only => [:index, :new]
|
|
before_filter :set_back_url, :only => [:new, :edit]
|
|
|
|
# GET /rates?user_id=1
|
|
# GET /rates.xml?user_id=1
|
|
def index
|
|
@rates = Rate.history_for_user(@user)
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.xml { render :xml => @rates }
|
|
end
|
|
end
|
|
|
|
# GET /rates/1
|
|
# GET /rates/1.xml
|
|
def show
|
|
@rate = Rate.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.xml { render :xml => @rate }
|
|
end
|
|
end
|
|
|
|
# GET /rates/new?user_id=1
|
|
# GET /rates/new.xml?user_id=1
|
|
def new
|
|
@rate = Rate.new(:user_id => @user.id)
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.xml { render :xml => @rate }
|
|
end
|
|
end
|
|
|
|
# GET /rates/1/edit
|
|
def edit
|
|
@rate = Rate.find(params[:id])
|
|
end
|
|
|
|
# POST /rates
|
|
# POST /rates.xml
|
|
def create
|
|
@rate = Rate.new(params[:rate])
|
|
|
|
respond_to do |format|
|
|
if @rate.save
|
|
flash[:notice] = 'Rate was successfully created.'
|
|
format.html {
|
|
if params[:back_url] && !params[:back_url].blank?
|
|
redirect_to(params[:back_url])
|
|
else
|
|
redirect_to(rates_url(:user_id => @rate.user_id))
|
|
end
|
|
}
|
|
format.xml { render :xml => @rate, :status => :created, :location => @rate }
|
|
else
|
|
format.html { render :action => "new" }
|
|
format.xml { render :xml => @rate.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /rates/1
|
|
# PUT /rates/1.xml
|
|
def update
|
|
@rate = Rate.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
if @rate.update_attributes(params[:rate])
|
|
flash[:notice] = 'Rate was successfully updated.'
|
|
format.html { redirect_to(@rate) }
|
|
format.xml { head :ok }
|
|
else
|
|
format.html { render :action => "edit" }
|
|
format.xml { render :xml => @rate.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /rates/1
|
|
# DELETE /rates/1.xml
|
|
def destroy
|
|
@rate = Rate.find(params[:id])
|
|
@rate.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to(rates_url) }
|
|
format.xml { head :ok }
|
|
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
|
|
|
|
def set_back_url
|
|
@back_url = params[:back_url]
|
|
end
|
|
end
|