product edits

This commit is contained in:
ohsab 2014-11-10 17:06:50 +01:00
parent c62b064128
commit d47e9af80c
7 changed files with 50 additions and 5 deletions

View file

@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
include ProductsHelper
private

View file

@ -17,8 +17,19 @@ class ProductsController < ApplicationController
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to @product
else
render 'edit'
end
end
private

View file

@ -1,2 +1,6 @@
module ProductsHelper
def current_product?(product)
product == current_product
end
end

View file

@ -6,6 +6,6 @@ class Product < ActiveRecord::Base
self.name ||= "FOOBAR"
self.sale_price ||= 0
self.purchase_price ||= 0
self.image_path = "/" #paperclip gem
self.image_path ||= "/" #paperclip gem
end
end

View file

@ -1,2 +1,26 @@
<h1>Products#edit</h1>
<p>Find me in app/views/products/edit.html.erb</p>
<h1>Product edit</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@product) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :purchase_price %>
<%= f.number_field :purchase_price %>
</br>
<%= f.label :sale_price %>
<%= f.number_field :sale_price %>
</br>
<%= f.label :image_path %>
<%= f.text_field :image_path %>
</br>
<%= f.submit "Update product", class: "btn btn-primary" %>
<% end %>
</div>
</div>

View file

@ -1,5 +1,8 @@
<h1>Products#show</h1>
<p>Find me in app/views/products/show.html.erb</p>
name: <%= @product.name %></br>
verkoop prijs: <%= @product.sale_price %> EUR</br>
aankoop prijs: <%= @product.purchase_price %> EUR</br>
verkoop prijs: <%= @product.sale_price %> EUR cent</br>
aankoop prijs: <%= @product.purchase_price %> EUR cent</br>
<%= link_to "Edit", edit_product_path(@product), class: "btn btn-lg btn-primary" %>

View file

@ -39,6 +39,8 @@ Rails.application.routes.draw do
resources :users
resources :orders
#product
resources :products
# The priority is based upon order of creation: first created -> highest priority.