2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
18 # handles CRUD on Portfolio records
19 class Objects::PortfolioController < ObjectsController
22 @portfolios, @total_pages = smr_paginate(
24 Portfolio.where(:id_user=>current_user.id).order(:name).to_a
29 # defines empty Portfolio to create() a new one
32 @portfolio = Portfolio.new(:date_created => Time.now.to_i)
41 @portfolio = Portfolio.find(params[:id])
46 # handles creates and updates
48 if params[:portfolio][:id].to_i > 0 then
49 p = Portfolio.where(:id=>params[:portfolio][:id], :id_user=>current_user.id).first
50 else p = Portfolio.new(portfolio_params) end
52 # hard-wired so noone spoofes it in here
53 p.id_user = current_user.id
54 p.date_created = Time.parse(params[:time_created]).to_i if params[:time_created]
56 # FIXME: not used any longer but required by schema, drop it?
58 if params[:portfolio][:id].to_i > 0 then
59 p.update(portfolio_params)
62 redirect_to objects_portfolio_index_path, :notice=>p.errors.full_messages.uniq.join(', ')
68 # internal helper defining parameters acceptable for Portfolio create/update
70 params.require(:portfolio).permit(
71 :id, :name, :date_created, :taxallowance, :order, :comment