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 FigureVar records
19 class Objects::FigurevarController < ObjectsController
22 @figurevars, @total_pages = smr_paginate(
24 FigureVar.where(:id_user=>[0,current_user.id]).order(:name).to_a
29 # defines empty FigureVar to create() a new one
31 @figurevar = FigureVar.new
35 # edit existing FigureVar
37 @figurevar = FigureVar.where(:id=>params[:id]).for_user(current_user.id).first
42 # handles creates and updates
44 if params[:figure_var][:id].to_i > 0 then
45 fv = FigureVar.where(:id=>params[:figure_var][:id]).for_user(current_user.id).first
46 else fv = FigureVar.new(figurevar_params) end
48 # hard-wired so noone spoofes it in here
49 # FIXME: how to handle properly? given 0 _or_ current user id
50 # fv.id_user = current_user.id
52 if params[:figure_var][:id].to_i > 0 then
53 fv.update(figurevar_params)
56 redirect_to objects_figurevar_index_path, :notice=>fv.errors.full_messages.uniq.join(', ')
62 # internal helper defining parameters acceptable for FigureVar create/update
64 params.require(:figure_var).permit(
65 :name, :unit, :expression, :comment,
66 :Bookmark_attributes=> [ :id, :name, :url, :rank ]