Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # MODAL PAGE
  2.  
  3. class Page < ActiveRecord::Base
  4. has_many :fragments, :as => :fragmentable
  5.  
  6. validates_presence_of :title, :slug
  7. validates_format_of :slug, :with => /^[[:alnum:]_]+$/
  8.  
  9. def to_param
  10. slug
  11. end
  12. end
  13.  
  14. # CONTROLLER PAGE
  15.  
  16. class PagesController < InheritedResources::Base
  17. respond_to :html, :xml
  18.  
  19. protected
  20.  
  21. def resource
  22. @page ||= end_of_association_chain.find_by_slug(params[:id])
  23. end
  24. end
  25.  
  26.  
  27. # MODAL FRAGMENT
  28.  
  29. class Fragment < ActiveRecord::Base
  30. belongs_to :fragmentable, :polymorphic => true
  31.  
  32. validates_presence_of :slug,:body
  33. validates_format_of :slug, :with => /^[[:alnum:]_]+$/
  34.  
  35. #def to_param
  36. # slug
  37. #end
  38. end
  39.  
  40. #CONTROLLER FRAGMENT
  41.  
  42. class FragmentsController < InheritedResources::Base
  43. respond_to :html, :js
  44. belongs_to :page, :polymorphic => true, :finder => :find_by_slug!
  45.  
  46. def create
  47. create! { url_for(parent) }
  48. end
  49.  
  50. def destroy
  51. destroy! do |format|
  52. format.html { redirect_to @page }
  53. end
  54. end
  55.  
  56. #protected
  57.  
  58. #def resource
  59. # @fragment ||= end_of_association_chain.find_by_slug(params[:id])
  60. #end
  61. end
Add Comment
Please, Sign In to add comment