Last active
December 24, 2015 23:49
-
-
Save rvanlieshout/6883580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= semantic_form_for @article, html: { class: 'form-horizontal' } do |f| | |
= f.inputs do | |
= f.input :name | |
= f.input :customer unless params.include?(:customer_id) | |
= f.input :number | |
= f.input :unit_price, as: :currency | |
= f.input :comments | |
= f.actions do | |
= f.action :submit, button_html: { class: 'btn btn-primary' } | |
= link_to t('cancel'), @article, class: 'btn' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! | |
%html | |
%head | |
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"} | |
%title= content_for?(:title) ? yield(:title) : "Aldor ERP" | |
%meta{:content => content_for?(:description) ? yield(:description) : "Aldor ERP", :name => "description"} | |
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true | |
= javascript_include_tag "application", "data-turbolinks-track" => true | |
= csrf_meta_tags | |
= yield(:head) | |
%body | |
#header | |
%h1= link_to 'Aldor ERP', root_path | |
#user-nav.navbar.navbar-inverse | |
%ul.nav.btn-group | |
%li.btn.btn-inverse | |
= link_to edit_user_registration_path do | |
%i.icon-user | |
%span.text Profiel | |
%li.btn.btn-inverse | |
= link_to destroy_user_session_path, method: :delete do | |
%i.icon-share-alt | |
%span.text Afmelden | |
#sidebar | |
= link_to root_path, class: 'visible-phone' do | |
%i.icon.icon-home | |
%span Dashboard | |
%ul | |
- if policy(Operation).create? | |
%li{class: menu_active_class('operations')} | |
= link_to operations_path do | |
%i.icon-cogs | |
%span= t('Operations') | |
%li{class: menu_active_class('operation_clusters')} | |
= link_to operation_clusters_path do | |
%i.icon-cogs | |
%span= t('OperationClusters') | |
%li{class: menu_active_class('articles')} | |
= link_to articles_path do | |
%i.icon-puzzle-piece | |
%span= t('Articles') | |
%li.submenu{ class: menu_open_class('suppliers','customers','users') } | |
= link_to '#', "data-no-turbolink" => "no-turbolink" do | |
%i.icon-user | |
%span= t('People') | |
%ul | |
- if policy(Supplier).create? | |
%li{class: menu_active_class('suppliers')} | |
= link_to suppliers_path do | |
%i.icon-truck | |
%span= t('Suppliers') | |
- if policy(Customer).create? | |
%li{class: menu_active_class('customers')} | |
= link_to customers_path do | |
%i.icon-user | |
%span= t('Customers') | |
- if policy(User).create? | |
%li{class: menu_active_class('users')} | |
= link_to users_path do | |
%i.icon-user | |
%span= t('Users') | |
%li{class: menu_active_class('document_categories')} | |
= link_to document_categories_path do | |
%i.icon-folder-open | |
%span= t('DocumentCategories') | |
#content | |
#content-header | |
- if content_for?(:content_header) | |
= yield :content_header | |
- else | |
%h1= yield(:page_title) || 'Geen page_title of content_header aanwezig' | |
#breadcrumb | |
- @breadcrumbs.each do |item| | |
= link_to item[:path], class: (item == @breadcrumbs.last ? 'current' : nil) do | |
- if item[:icon] | |
%i{class: "icon-#{item[:icon]}"} | |
= item[:title] | |
.container-fluid | |
- if flash.any? | |
.row-fluid | |
.span12 | |
= bootstrap_flash | |
= yield | |
#tooltip-container | |
.row-fluid | |
#footer.span12 | |
%p Aldor ERP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlePolicy < Struct.new(:current_user, :article) | |
class Scope < Struct.new(:current_user, :articles) | |
def resolve | |
if current_user.present? && current_user.admin? | |
articles | |
else | |
articles.none | |
end | |
end | |
end | |
def new? | |
current_user.present? && current_user.admin? | |
end | |
alias_method :create?, :new? | |
alias_method :show?, :new? | |
alias_method :edit?, :new? | |
alias_method :update?, :new? | |
alias_method :destroy?, :new? | |
alias_method :apply_cluster?, :new? | |
def permitted_attributes | |
[ | |
:customer_id, | |
:number, | |
:unit_price, | |
:name, | |
:comments, | |
:apply_operation_cluster_id | |
] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
before_action :set_breadcrumb | |
def index | |
@articles = policy_scope(Article.all).includes(:customer).order("customers.company_name, name") | |
@articles = @articles.filter(params[:query], :company_name, :name, :number) if params[:query] | |
@articles = @articles.page params[:page] | |
end | |
def show | |
authorize @article | |
end | |
def new | |
@article = Article.new | |
authorize @article | |
end | |
def create | |
if @customer | |
@article = @customer.articles.build(article_attributes) | |
else | |
@article = Article.new(article_attributes) | |
end | |
authorize @article | |
if @article.save | |
redirect_to @article, notice: t('notices.created', model: t('Article')) | |
else | |
render :new | |
end | |
end | |
def edit | |
authorize @article | |
end | |
def update | |
authorize @article | |
if @article.update_attributes(article_attributes) | |
redirect_to @article, notice: t('notices.updated', model: t('Article')) | |
elsif article_attributes.include?(:apply_operation_cluster_id) | |
@operation_clusters = policy_scope(OperationCluster.all).order(:name) | |
render :apply_cluster | |
else | |
render :edit | |
end | |
end | |
def destroy | |
authorize @article | |
@article.destroy | |
redirect_to @customer, notice: t('notices.destroyed', model: t('Article')) | |
end | |
def apply_cluster | |
authorize @article | |
@operation_clusters = policy_scope(OperationCluster.all).order(:name) | |
end | |
private | |
def article_attributes | |
params.require(:article).permit(policy(Article).permitted_attributes) | |
end | |
def set_breadcrumb | |
params[:id] && @article = Article.find(params[:id]) | |
params[:customer_id] && @customer = Customer.find(params[:customer_id]) | |
@customer = @article.customer if @article | |
@breadcrumbs << { path: customers_path, title: t('Customers'), icon: 'user' } | |
@breadcrumbs << { path: @customer, title: @customer.company_name, icon: 'user' } if @customer | |
@breadcrumbs << { path: articles_path, title: t('Articles'), icon: 'puzzle-piece' } | |
@breadcrumbs << { path: @article, title: @article.name, icon: 'puzzle-piece' } if @article | |
@breadcrumbs << { path: [:apply_cluster, @article], title: t('.breadcrumb'), icon: 'cogs' } if params[:action] == "apply_cluster" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/articles/new" for 213.93.230.243 at 2013-10-08 13:51:27 +0200 | |
Processing by ArticlesController#new as HTML | |
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 | |
Ability Load (0.3ms) SELECT `abilities`.* FROM `abilities` WHERE `abilities`.`user_id` = 1 AND `abilities`.`key` = 'all' | |
Customer Load (0.3ms) SELECT `customers`.* FROM `customers` | |
Rendered articles/_form.html.haml (51.3ms) | |
Rendered articles/new.html.haml within layouts/application (53.9ms) | |
Completed 500 Internal Server Error in 66ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- content_for :content_header do | |
%h1 | |
= page_title t('.title') | |
.widget-box | |
.widget-title | |
%span.icon | |
%i.icon-th | |
%h5= t('properties') | |
.widget-content.nopadding | |
= render 'form' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment