From 747b8d9c4bb8e7244ad1c2de323c125ee6d630e4 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sat, 8 Dec 2012 16:56:50 -0500 Subject: [PATCH] Added bike models controller and views --- app/controllers/bike_models_controller.rb | 30 +++++++++++++++++++++++ app/views/bike_models/_form.html.haml | 12 +++++++++ app/views/bike_models/index.html.haml | 17 +++++++++++++ app/views/bike_models/new.html.haml | 4 +++ app/views/bike_models/show.html.haml | 15 ++++++++++++ config/routes.rb | 1 + 6 files changed, 79 insertions(+) create mode 100644 app/controllers/bike_models_controller.rb create mode 100644 app/views/bike_models/_form.html.haml create mode 100644 app/views/bike_models/index.html.haml create mode 100644 app/views/bike_models/new.html.haml create mode 100644 app/views/bike_models/show.html.haml diff --git a/app/controllers/bike_models_controller.rb b/app/controllers/bike_models_controller.rb new file mode 100644 index 0000000..658722e --- /dev/null +++ b/app/controllers/bike_models_controller.rb @@ -0,0 +1,30 @@ +class BikeModelsController < AuthenticatedController + expose(:bike_model) do + if params[:id] + BikeModel.find(params[:id]) + elsif params[:bike_model] + BikeModel.new(params[:bike_model]) + else + BikeModel.new + end + end + + expose(:bike_models) { BikeModel.order('id').paginate(:page => params[:page]) } + + def index + end + + def show + end + + def new + end + + def create + if bike_model.save + redirect_to bike_models_url + else + render :new + end + end +end diff --git a/app/views/bike_models/_form.html.haml b/app/views/bike_models/_form.html.haml new file mode 100644 index 0000000..6369613 --- /dev/null +++ b/app/views/bike_models/_form.html.haml @@ -0,0 +1,12 @@ += form_for bike_model, :html => { :class => 'form-horizontal' } do |f| + .control-group + = f.label :model, :class => 'control-label' + .controls + = f.text_field :model, :class => 'text_field' + .control-group + = f.label :bike_brand_id, :class => 'control-label' + .controls + = f.number_field :bike_brand_id, :class => 'number_field' + .form-actions + = f.submit nil, :class => 'btn btn-primary' + = link_to t('.cancel', :default => t("helpers.links.cancel")), bike_models_path, :class => 'btn' diff --git a/app/views/bike_models/index.html.haml b/app/views/bike_models/index.html.haml new file mode 100644 index 0000000..463576e --- /dev/null +++ b/app/views/bike_models/index.html.haml @@ -0,0 +1,17 @@ +- model_class = BikeModel.new.class +.page-header + %h1=t '.title', :default => model_class.model_name.human.pluralize +%table.table.table-striped + %thead + %tr + %th= model_class.human_attribute_name(:id) + %th= model_class.human_attribute_name(:model) + %th= model_class.human_attribute_name(:bike_brand_id) + %tbody + - bike_models.each do |bike_model| + %tr + %td= link_to bike_model.id, bike_model_path(bike_model) + %td= bike_model.model + %td= link_to bike_model.brand, bike_brand_path(bike_model.brand) += will_paginate bike_models += link_to t('.new', :default => t("helpers.links.new")), new_bike_model_path, :class => 'btn btn-primary' diff --git a/app/views/bike_models/new.html.haml b/app/views/bike_models/new.html.haml new file mode 100644 index 0000000..bb5ebd9 --- /dev/null +++ b/app/views/bike_models/new.html.haml @@ -0,0 +1,4 @@ +- model_class = @bike_model.class +.page-header + %h1=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}") += render :partial => "form" diff --git a/app/views/bike_models/show.html.haml b/app/views/bike_models/show.html.haml new file mode 100644 index 0000000..8e706c0 --- /dev/null +++ b/app/views/bike_models/show.html.haml @@ -0,0 +1,15 @@ +- model_class = bike_model.class +.page-header + %h1=t '.title', :default => model_class.model_name.human + +%p + %strong= model_class.human_attribute_name(:model) + ':' + %br + = bike_model.model +%p + %strong= model_class.human_attribute_name(:bike_brand_id) + ':' + %br + = link_to bike_model.brand, bike_brand_path(bike_model.brand) + +.form-actions + = link_to t('.back', :default => t("helpers.links.back")), bike_models_path, :class => 'btn' diff --git a/config/routes.rb b/config/routes.rb index b624da3..4687b10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,7 @@ Velocipede::Application.routes.draw do match 'site/index' => 'site#index' resources :bike_brands, :except => [:edit, :delete] + resources :bike_models, :except => [:edit, :delete] #resources :clues #resources :maps