Skip to content

Commit

Permalink
#11
Browse files Browse the repository at this point in the history
Add, remove and update pages from the story edit page
  • Loading branch information
Isaac Freeman committed Apr 27, 2014
1 parent 168a9bf commit 89e9050
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/admin/stories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
form do |f|
f.inputs "Story" do
f.input :name
f.input :description
f.input :cover_image
f.input :people, as: :select, collection: Person.alphabetical
f.has_many :pages, for: [:pages, f.object.pages.ordered], :allow_destroy => true, :heading => 'Pages', :new_record => true do |pf|
pf.input :position
pf.input :image, :hint => pf.template.image_tag(pf.object.image.url(:thumb))
end
end

f.buttons
Expand Down
4 changes: 3 additions & 1 deletion app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ class Story < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :history]

attr_accessible :cover_image, :cover_image_file_name, :cover_image_content_type, :cover_image_file_size, :cover_image_updated_at, :name, :story_pages, :story_pages_attributes, :person_ids, :description
attr_accessible :cover_image, :cover_image_file_name, :cover_image_content_type, :cover_image_file_size, :cover_image_updated_at, :name, :story_pages, :pages_attributes, :person_ids, :description
has_attached_file :cover_image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/default_images/:style/story.png"
has_many :pages
has_and_belongs_to_many :people

accepts_nested_attributes_for :pages, :allow_destroy => true

scope :alphabetical, order("name ASC")
scope :recent, ->(num) { order('updated_at DESC').limit(num) }

Expand Down

0 comments on commit 89e9050

Please sign in to comment.