Class: RatesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RatesController
- Includes:
- SortHelper
- Defined in:
- app/controllers/rates_controller.rb
Constant Summary collapse
- ValidSortOptions =
{'date_in_effect' => "#{Rate.table_name}.date_in_effect", 'project_id' => "#{Project.table_name}.name"}
Instance Method Summary collapse
-
#create ⇒ Object
POST /rates POST /rates.xml.
-
#destroy ⇒ Object
DELETE /rates/1 DELETE /rates/1.xml.
-
#edit ⇒ Object
GET /rates/1/edit.
-
#index ⇒ Object
GET /rates?user_id=1 GET /rates.xml?user_id=1.
-
#new ⇒ Object
GET /rates/new?user_id=1 GET /rates/new.xml?user_id=1.
-
#show ⇒ Object
GET /rates/1 GET /rates/1.xml.
-
#update ⇒ Object
PUT /rates/1 PUT /rates/1.xml.
Instance Method Details
#create ⇒ Object
POST /rates POST /rates.xml
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/rates_controller.rb', line 56 def create @rate = Rate.new(params[:rate]) respond_to do |format| if @rate.save format.html { flash[:notice] = 'Rate was successfully created.' redirect_back_or_default(rates_url(:user_id => @rate.user_id)) } format.xml { render :xml => @rate, :status => :created, :location => @rate } format.js { render :action => 'create.js.rjs'} else format.html { render :action => "new" } format.xml { render :xml => @rate.errors, :status => :unprocessable_entity } format.js { flash.now[:error] = 'Error creating a new Rate.' render :action => 'create_error.js.rjs' } end end end |
#destroy ⇒ Object
DELETE /rates/1 DELETE /rates/1.xml
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/rates_controller.rb', line 102 def destroy @rate = Rate.find(params[:id]) @rate.destroy respond_to do |format| format.html { flash[:error] = "Rate is locked and cannot be deleted" if @rate.locked? redirect_back_or_default(rates_url(:user_id => @rate.user_id)) } format.xml { head :ok } end end |
#edit ⇒ Object
GET /rates/1/edit
50 51 52 |
# File 'app/controllers/rates_controller.rb', line 50 def edit @rate = Rate.find(params[:id]) end |
#index ⇒ Object
GET /rates?user_id=1 GET /rates.xml?user_id=1
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/rates_controller.rb', line 15 def index sort_init "#{Rate.table_name}.date_in_effect", "desc" sort_update ValidSortOptions @rates = Rate.history_for_user(@user, sort_clause) respond_to do |format| format.html { render :action => 'index', :layout => !request.xhr?} format.xml { render :xml => @rates } end end |
#new ⇒ Object
GET /rates/new?user_id=1 GET /rates/new.xml?user_id=1
40 41 42 43 44 45 46 47 |
# File 'app/controllers/rates_controller.rb', line 40 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 |
#show ⇒ Object
GET /rates/1 GET /rates/1.xml
29 30 31 32 33 34 35 36 |
# File 'app/controllers/rates_controller.rb', line 29 def show @rate = Rate.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @rate } end end |
#update ⇒ Object
PUT /rates/1 PUT /rates/1.xml
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/rates_controller.rb', line 80 def update @rate = Rate.find(params[:id]) respond_to do |format| # Locked rates will fail saving here. if @rate.update_attributes(params[:rate]) flash[:notice] = 'Rate was successfully updated.' format.html { redirect_back_or_default(rates_url(:user_id => @rate.user_id)) } format.xml { head :ok } else if @rate.locked? flash[:error] = "Rate is locked and cannot be edited" @rate.reload # Removes attribute changes end format.html { render :action => "edit" } format.xml { render :xml => @rate.errors, :status => :unprocessable_entity } end end end |