Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MODAL PAGE
- class Page < ActiveRecord::Base
- has_many :fragments, :as => :fragmentable
- validates_presence_of :title, :slug
- validates_format_of :slug, :with => /^[[:alnum:]_]+$/
- def to_param
- slug
- end
- end
- # CONTROLLER PAGE
- class PagesController < InheritedResources::Base
- respond_to :html, :xml
- protected
- def resource
- @page ||= end_of_association_chain.find_by_slug(params[:id])
- end
- end
- # MODAL FRAGMENT
- class Fragment < ActiveRecord::Base
- belongs_to :fragmentable, :polymorphic => true
- validates_presence_of :slug,:body
- validates_format_of :slug, :with => /^[[:alnum:]_]+$/
- #def to_param
- # slug
- #end
- end
- #CONTROLLER FRAGMENT
- class FragmentsController < InheritedResources::Base
- respond_to :html, :js
- belongs_to :page, :polymorphic => true, :finder => :find_by_slug!
- def create
- create! { url_for(parent) }
- end
- def destroy
- destroy! do |format|
- format.html { redirect_to @page }
- end
- end
- #protected
- #def resource
- # @fragment ||= end_of_association_chain.find_by_slug(params[:id])
- #end
- end
Add Comment
Please, Sign In to add comment