diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 11e2cc1..5e44107 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -56,6 +56,10 @@ input { height: auto !important; } +/* boostrap */ +body { + padding-top: 80px; +} /* footer */ diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 1cc8cd7..65b79e7 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -6,16 +6,12 @@ class ProductsController < ApplicationController def create @product = Product.new(product_params) if @product.save - redirect_to @product + redirect_to action: :index else - render 'new' + render :new end end - def show - @product = Product.find(params[:id]) - end - def index @products = Product.all end @@ -27,7 +23,8 @@ class ProductsController < ApplicationController def update @product = Product.find(params[:id]) if @product.update_attributes(product_params) - redirect_to @product + flash[:success] = "Succesfully updated product" + redirect_to action: :index else render 'edit' end @@ -35,6 +32,7 @@ class ProductsController < ApplicationController def destroy Product.find(params[:id]).destroy + flash[:success] = "Succesfully removed product" redirect_to products_path end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1632fc1..e3e4677 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,10 +9,58 @@ module ApplicationHelper @style = "background-color: #"+ get_color(user) +";" end + def euro(f) + "€#{number_with_precision f, precision: 2}" + end + #tijdelijk voor layout def koelkast(status) @koelkast ||= status end + # Form helpers + def form_errors(object) + render partial: "form_errors", locals: {object: object} + end + + def form_text_field(f, tag) + render partial: "form_text_field", locals: {f: f, tag: tag} + end + + def form_password_field(f, tag) + render partial: "form_password_field", locals: {f: f, tag: tag} + end + + def form_text_area(f, tag) + render partial: "form_text_area", locals: {f: f, tag: tag} + end + + def form_fancy_text_area(f, tag) + render partial: "form_fancy_text_area", locals: {f: f, tag: tag} + end + + def form_email_field(f, tag) + render partial: "form_email_field", locals: {f: f, tag: tag} + end + + def form_date_field(f, tag, id, value) + render partial: "form_date_field", locals: {f: f, tag: tag, id: id, value: value} + end + + def form_number_field(f, tag) + render partial: "form_number_field", locals: {f: f, tag: tag} + end + + def form_collection_select(f, *args) + # This line enable passing optional arguments such as include_blank to the + # partial. If nothing is passed, an empty options hash is appended. + args << {} if args.length < 5 + + render partial: "form_collection_select", locals: {f: f, args: args} + end + + def form_check_box(f, tag) + render partial: "form_check_box", locals: {f: f, tag: tag} + end end diff --git a/app/models/product.rb b/app/models/product.rb index c7c31f7..4463062 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -24,4 +24,14 @@ class Product < ActiveRecord::Base def count(order) order_products.find_by(order: order).count end + + def price + (read_attribute(:price) || 0) / 100.0 + end + + def price=(value) + if value.is_a? String then value.sub!(',', '.') end + write_attribute(:price, (value.to_f * 100).to_int) + end + end diff --git a/app/views/application/_errors.html.erb b/app/views/application/_errors.html.erb index d7c0fb2..6a3452e 100644 --- a/app/views/application/_errors.html.erb +++ b/app/views/application/_errors.html.erb @@ -1,5 +1,14 @@ - +<% if model.errors.any? %> +
+
+ <%= pluralize(model.errors.count, "error") %> prohibited this <%= model.class.name.downcase %> from being saved: +
+
+ +
+
+<% end %> diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb new file mode 100644 index 0000000..312b24d --- /dev/null +++ b/app/views/application/_flash.html.erb @@ -0,0 +1,26 @@ +
+ <% if flash[:error] %> +
+ + Error! <%= flash[:error] %> +
+ <% end %> + <% if flash[:success] %> +
+ + Success! <%= flash[:success] %> +
+ <% end %> + <% if flash[:notice] %> +
+ + Notice! <%= flash[:notice] %> +
+ <% end %> + <% if flash[:warning] %> +
+ + Warning! <%= flash[:warning] %> +
+ <% end %> +
diff --git a/app/views/application/_form_check_box.html.erb b/app/views/application/_form_check_box.html.erb new file mode 100644 index 0000000..8d8e429 --- /dev/null +++ b/app/views/application/_form_check_box.html.erb @@ -0,0 +1,6 @@ +
+ + <%= f.check_box tag %> +
diff --git a/app/views/application/_form_collection_select.html.erb b/app/views/application/_form_collection_select.html.erb new file mode 100644 index 0000000..99bd7e5 --- /dev/null +++ b/app/views/application/_form_collection_select.html.erb @@ -0,0 +1,5 @@ +<%# To pass options to the collection_select, add {options} as the last argument %> +
+ <%= f.label args.first %>: + <%= f.collection_select *args, {class: 'form-control'} %> +
diff --git a/app/views/application/_form_date_field.html.erb b/app/views/application/_form_date_field.html.erb new file mode 100644 index 0000000..31cbe37 --- /dev/null +++ b/app/views/application/_form_date_field.html.erb @@ -0,0 +1,7 @@ +
+ <%= f.label tag %>: +
+ + <%= f.text_field tag, class: 'form-control', id: id, value: value %> +
+
diff --git a/app/views/application/_form_email_field.html.erb b/app/views/application/_form_email_field.html.erb new file mode 100644 index 0000000..c60dbd8 --- /dev/null +++ b/app/views/application/_form_email_field.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.email_field tag, class: 'form-control' %> +
diff --git a/app/views/application/_form_errors.html.erb b/app/views/application/_form_errors.html.erb new file mode 100644 index 0000000..18c5c18 --- /dev/null +++ b/app/views/application/_form_errors.html.erb @@ -0,0 +1,14 @@ +<% if object.errors.any? %> +
+
+ <%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.name.downcase %> from being saved: +
+
+ +
+
+<% end %> diff --git a/app/views/application/_form_fancy_text_area.html.erb b/app/views/application/_form_fancy_text_area.html.erb new file mode 100644 index 0000000..32bb3db --- /dev/null +++ b/app/views/application/_form_fancy_text_area.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.text_area tag, class: 'form-control ckeditor' %> +
diff --git a/app/views/application/_form_number_field.html.erb b/app/views/application/_form_number_field.html.erb new file mode 100644 index 0000000..5baa83e --- /dev/null +++ b/app/views/application/_form_number_field.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.number_field tag, class: 'form-control', min: 0 %> +
diff --git a/app/views/application/_form_password_field.html.erb b/app/views/application/_form_password_field.html.erb new file mode 100644 index 0000000..54e670a --- /dev/null +++ b/app/views/application/_form_password_field.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.password_field tag, class: 'form-control' %> +
diff --git a/app/views/application/_form_text_area.html.erb b/app/views/application/_form_text_area.html.erb new file mode 100644 index 0000000..256bfb7 --- /dev/null +++ b/app/views/application/_form_text_area.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.text_area tag, class: 'form-control' %> +
diff --git a/app/views/application/_form_text_field.html.erb b/app/views/application/_form_text_field.html.erb new file mode 100644 index 0000000..7390ad4 --- /dev/null +++ b/app/views/application/_form_text_field.html.erb @@ -0,0 +1,4 @@ +
+ <%= f.label tag %>: + <%= f.text_field tag, class: 'form-control' %> +
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index 5d7474d..018625a 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -1,13 +1,12 @@ diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 9549175..322431c 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,7 +1,12 @@ -