Skip to content

Commit

Permalink
added section_id to story and added associations to models (whoops! f…
Browse files Browse the repository at this point in the history
…orgot those before!) ... also fixed some problems with the dynamically generated tabs... @Sections was not available everywhere... now it is, but in a very WET fashion... refactor that later
  • Loading branch information
brandondrew committed Aug 29, 2008
1 parent bc558ec commit 769bb7d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/application.rb
Expand Up @@ -12,5 +12,6 @@ class ApplicationController < ActionController::Base
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
# filter_parameter_logging :password
@sections = Section.find(:all)

end
7 changes: 7 additions & 0 deletions app/controllers/photos_controller.rb
Expand Up @@ -2,6 +2,7 @@ class PhotosController < ApplicationController
# GET /photos
# GET /photos.xml
def index
@sections = Section.find(:all)
@photos = Photo.find(:all)

respond_to do |format|
Expand All @@ -13,6 +14,7 @@ def index
# GET /photos/1
# GET /photos/1.xml
def show
@sections = Section.find(:all) # TODO : refactor so I don't repeat myself so much!
@photo = Photo.find(params[:id])

respond_to do |format|
Expand All @@ -24,6 +26,7 @@ def show
# GET /photos/new
# GET /photos/new.xml
def new
@sections = Section.find(:all)
@photo = Photo.new

respond_to do |format|
Expand All @@ -34,12 +37,14 @@ def new

# GET /photos/1/edit
def edit
@sections = Section.find(:all)
@photo = Photo.find(params[:id])
end

# POST /photos
# POST /photos.xml
def create
@sections = Section.find(:all)
@photo = Photo.new(params[:photo])

respond_to do |format|
Expand All @@ -57,6 +62,7 @@ def create
# PUT /photos/1
# PUT /photos/1.xml
def update
@sections = Section.find(:all)
@photo = Photo.find(params[:id])

respond_to do |format|
Expand All @@ -74,6 +80,7 @@ def update
# DELETE /photos/1
# DELETE /photos/1.xml
def destroy
@sections = Section.find(:all)
@photo = Photo.find(params[:id])
@photo.destroy

Expand Down
6 changes: 6 additions & 0 deletions app/controllers/sections_controller.rb
Expand Up @@ -13,6 +13,7 @@ def index
# GET /sections/1
# GET /sections/1.xml
def show
@sections = Section.find(:all)
@section = Section.find(params[:id])

respond_to do |format|
Expand All @@ -24,6 +25,7 @@ def show
# GET /sections/new
# GET /sections/new.xml
def new
@sections = Section.find(:all) # TODO: refactor so I don't have to repeat this all over the place
@section = Section.new

respond_to do |format|
Expand All @@ -34,12 +36,14 @@ def new

# GET /sections/1/edit
def edit
@sections = Section.find(:all)
@section = Section.find(params[:id])
end

# POST /sections
# POST /sections.xml
def create
@sections = Section.find(:all)
@section = Section.new(params[:section])

respond_to do |format|
Expand All @@ -57,6 +61,7 @@ def create
# PUT /sections/1
# PUT /sections/1.xml
def update
@sections = Section.find(:all)
@section = Section.find(params[:id])

respond_to do |format|
Expand All @@ -74,6 +79,7 @@ def update
# DELETE /sections/1
# DELETE /sections/1.xml
def destroy
@sections = Section.find(:all)
@section = Section.find(params[:id])
@section.destroy

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/stories_controller.rb
Expand Up @@ -2,6 +2,7 @@ class StoriesController < ApplicationController
# GET /stories
# GET /stories.xml
def index
@sections = Section.find(:all)
@stories = Story.find(:all)

respond_to do |format|
Expand All @@ -13,6 +14,7 @@ def index
# GET /stories/1
# GET /stories/1.xml
def show
@sections = Section.find(:all) # TODO: refactor to DRY this out
@story = Story.find(params[:id])

respond_to do |format|
Expand All @@ -24,6 +26,7 @@ def show
# GET /stories/new
# GET /stories/new.xml
def new
@sections = Section.find(:all)
@story = Story.new

respond_to do |format|
Expand All @@ -34,13 +37,15 @@ def new

# GET /stories/1/edit
def edit
@sections = Section.find(:all)
@story = Story.find(params[:id])

end

# POST /stories
# POST /stories.xml
def create
@sections = Section.find(:all)
@story = Story.new(params[:story])

respond_to do |format|
Expand All @@ -58,6 +63,7 @@ def create
# PUT /stories/1
# PUT /stories/1.xml
def update
@sections = Section.find(:all)
@story = Story.find(params[:id])

respond_to do |format|
Expand All @@ -75,6 +81,7 @@ def update
# DELETE /stories/1
# DELETE /stories/1.xml
def destroy
@sections = Section.find(:all)
@story = Story.find(params[:id])
@story.destroy

Expand Down
4 changes: 4 additions & 0 deletions app/models/section.rb
@@ -1,5 +1,9 @@
class Section < ActiveRecord::Base

has_many :stories



def is_tab_check
if self.is_tab
"&#10003;" # checkmark HTML entity... TODO: test for support, this might need to be changed
Expand Down
3 changes: 3 additions & 0 deletions app/models/story.rb
@@ -1,4 +1,7 @@
class Story < ActiveRecord::Base

belongs_to :section # section_id

has_many :photo_placements
has_many :photos, :through => :photo_placements

Expand Down
8 changes: 5 additions & 3 deletions config/routes.rb
Expand Up @@ -2,9 +2,11 @@

# map.sections 'sections/:id', :controller => "sections", :action => "index"

map.resources :sections do |sections|
sections.resources :stories
end
# map.resources :sections do |sections|
# sections.resources :stories
# end

map.resources :sections

map.resources :photos

Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20080829052346_add_section_id_to_story.rb
@@ -0,0 +1,9 @@
class AddSectionIdToStory < ActiveRecord::Migration
def self.up
add_column :stories, :section_id, :integer
end

def self.down
remove_column :stories, :section_id
end
end

0 comments on commit 769bb7d

Please sign in to comment.