Skip to content

Instantly share code, notes, and snippets.

@walidvb
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidvb/b7f3b58c56b3c9b46d90 to your computer and use it in GitHub Desktop.
Save walidvb/b7f3b58c56b3c9b46d90 to your computer and use it in GitHub Desktop.
has_one :splash_page, :dependent => :destroy
accepts_nested_attributes_for :splash_page, :allow_destroy => true, reject_if: proc { |attributes| !SplashPage.new(attributes).valid? }
form do |f|
f.inputs "Splash page", :id => "splash-page" do
f.inputs :splash_page, :allow_destroy => true, for: [:splash_page, (f.object.splash_page || SplashPage.new)] do |s|
s.input :active
#these fields disappear
s.input :thumbnail, :as => :file, :hint => link_to(image_tag(s.object.thumbnail.url(:thumb)), s.object.thumbnail.url) unless s.object.new_record?
s.input :header_image, :as => :file, :hint => link_to(image_tag(s.object.header_image.url(:thumb)), s.object.header_image.url) unless s.object.new_record?
end
end
end
validates_presence_of :button_call_to_action, :unless => Proc.new { |c| !c.active? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment