Permalink
Browse files

markup fix

  • Loading branch information...
1 parent 87b7f64 commit 4c4fe09f22b3e8f3eb716cf16abc1221700aa0b4 @barthezslavik committed Dec 22, 2012
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Categories controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -9,3 +9,18 @@ p, a
float: left
width: 150px
margin: 5px 10px 4px 0
+
+.left
+ width: 500px
+ float: left
+
+.right
+ width: 300px
+ float: left
+
+.both
+ clear: both
+
+pre
+ background: #D7E7EF
+ width: 500px
@@ -0,0 +1,83 @@
+class CategoriesController < ApplicationController
+ # GET /categories
+ # GET /categories.json
+ def index
+ @categories = Category.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @categories }
+ end
+ end
+
+ # GET /categories/1
+ # GET /categories/1.json
+ def show
+ @category = Category.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @category }
+ end
+ end
+
+ # GET /categories/new
+ # GET /categories/new.json
+ def new
+ @category = Category.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @category }
+ end
+ end
+
+ # GET /categories/1/edit
+ def edit
+ @category = Category.find(params[:id])
+ end
+
+ # POST /categories
+ # POST /categories.json
+ def create
+ @category = Category.new(params[:category])
+
+ respond_to do |format|
+ if @category.save
+ format.html { redirect_to @category, notice: 'Category was successfully created.' }
+ format.json { render json: @category, status: :created, location: @category }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @category.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /categories/1
+ # PUT /categories/1.json
+ def update
+ @category = Category.find(params[:id])
+
+ respond_to do |format|
+ if @category.update_attributes(params[:category])
+ format.html { redirect_to @category, notice: 'Category was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @category.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /categories/1
+ # DELETE /categories/1.json
+ def destroy
+ @category = Category.find(params[:id])
+ @category.destroy
+
+ respond_to do |format|
+ format.html { redirect_to categories_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -2,7 +2,9 @@ class SamplesController < ApplicationController
# GET /samples
# GET /samples.json
def index
- @samples = Sample.all
+ category_id = Category.find_by_name("Main")
+ @samples = Sample.find_all_by_category_id(category_id)
+ @categories = Category.all
respond_to do |format|
format.html # index.html.erb
@@ -0,0 +1,2 @@
+module CategoriesHelper
+end
@@ -0,0 +1,5 @@
+class Category < ActiveRecord::Base
+ attr_accessible :name
+
+ has_many :samples
+end
@@ -1,4 +1,6 @@
class Sample < ActiveRecord::Base
has_attached_file :screenshot, :styles => {:large => "500x500>", :medium => "300x300>", :thumb => "100x100>" }
- attr_accessible :description, :name, :screenshot
+ attr_accessible :description, :name, :screenshot, :demo, :category_id
+
+ belongs_to :category
end
@@ -0,0 +1,8 @@
+= simple_form_for(@category) do |f|
+ = f.error_notification
+
+ .inputs
+ = f.input :name
+
+ .actions
+ = f.button :submit
@@ -0,0 +1,7 @@
+%h1 Editing category
+
+= render 'form'
+
+= link_to 'Show', @category
+\|
+= link_to 'Back', categories_path
@@ -0,0 +1,19 @@
+%h1 Listing categories
+
+%table
+ %tr
+ %th Name
+ %th
+ %th
+ %th
+
+ - @categories.each do |category|
+ %tr
+ %td= category.name
+ %td= link_to 'Show', category
+ %td= link_to 'Edit', edit_category_path(category)
+ %td= link_to 'Destroy', category, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Category', new_category_path
@@ -0,0 +1,5 @@
+%h1 New category
+
+= render 'form'
+
+= link_to 'Back', categories_path
@@ -0,0 +1,9 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @category.name
+
+= link_to 'Edit', edit_category_path(@category)
+\|
+= link_to 'Back', categories_path
No changes.
@@ -1,8 +1,14 @@
= simple_form_for @sample do |f|
.inputs.clearfix
= f.input :name
+ %br
= f.input :description
+ %br
= f.input :screenshot, :as => :file
+ %br
= f.input :demo
+ %br
+ = f.association :category, :collection => Category.all(:order => 'name'), :prompt => "Choose a Category"
+ %br
.actions.clearfix
= f.submit 'Save'
@@ -1,10 +1,20 @@
%p#notice= notice
-%h2= @sample.name
+.left
+ %h2= @sample.name
+.right
+ %br
+ = link_to 'Edit', edit_sample_path(@sample)
+
+%br
+%br.both
+
%pre= @sample.description
- if @sample.screenshot_file_name?
=link_to image_tag(@sample.screenshot.url :large), @sample.screenshot.url
+%br
+=link_to "Demo", "/#{@sample.demo}"
+
-/= link_to 'Edit', edit_sample_path(@sample)
/= link_to 'Back', samples_path
View
@@ -1,4 +1,7 @@
Solution::Application.routes.draw do
+ resources :categories
+
+
resources :samples
@@ -0,0 +1,9 @@
+class CreateCategories < ActiveRecord::Migration
+ def change
+ create_table :categories do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,5 @@
+class AddCategoryIdToSamples < ActiveRecord::Migration
+ def change
+ add_column :samples, :category_id, :integer
+ end
+end
View
@@ -11,7 +11,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121222111037) do
+ActiveRecord::Schema.define(:version => 20121222140829) do
+
+ create_table "categories", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "samples", :force => true do |t|
t.string "name"
@@ -23,6 +29,8 @@
t.string "screenshot_content_type"
t.integer "screenshot_file_size"
t.datetime "screenshot_updated_at"
+ t.string "demo"
+ t.integer "category_id"
end
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class CategoriesControllerTest < ActionController::TestCase
+ setup do
+ @category = categories(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:categories)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create category" do
+ assert_difference('Category.count') do
+ post :create, category: { name: @category.name }
+ end
+
+ assert_redirected_to category_path(assigns(:category))
+ end
+
+ test "should show category" do
+ get :show, id: @category
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @category
+ assert_response :success
+ end
+
+ test "should update category" do
+ put :update, id: @category, category: { name: @category.name }
+ assert_redirected_to category_path(assigns(:category))
+ end
+
+ test "should destroy category" do
+ assert_difference('Category.count', -1) do
+ delete :destroy, id: @category
+ end
+
+ assert_redirected_to categories_path
+ end
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CategoriesHelperTest < ActionView::TestCase
+end

0 comments on commit 4c4fe09

Please sign in to comment.