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 Stock records
21 # * this controller is called "Stock" since the model is still Stock. It
22 # will become "Security" when support for different types of paper is
23 # implemented (Bonds, Funds, Currency, ...).
24 # * until then we talk to the user about "Securities" already
26 class Objects::StockController < ObjectsController
29 @stocks = Stock.order(:name).paginate(:page => params[:page])
32 @symbolextensions = StockSymbolextension.all
33 @quotesources = StockQuotesource.all
37 # retrieve Stock for editing
40 @stock = Stock.find(params[:id])
45 # handles creates and updates
46 # FIXME: :annual_meeting is broken and hardwired, better drop it?
48 if params[:stock][:id].to_i > 0 then
49 s = Stock.find(params[:stock][:id])
50 else s = Stock.new(stock_params) end
52 s.annual_meeting = "1970-01-01"
54 if params[:stock][:id].to_i > 0 then
55 s.update(stock_params)
58 redirect_to objects_stock_index_path, :notice=>s.errors.full_messages.uniq.join(', ')
64 # internal helper defining parameters acceptable for Stock create/update
66 params.require(:stock).permit(
67 :name, :symbol, :id_stock_symbolextension, :id_stock_quotesource,