Last active
December 20, 2015 11:19
-
-
Save mdunbavan/6122822 to your computer and use it in GitHub Desktop.
Formtastic setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My active admin spotlight model(where form is displayed to add new): | |
ActiveAdmin.register Spotlight do | |
form do |f| | |
f.inputs do | |
f.input :video | |
f.input :image | |
f.input :description | |
f.input :band, :as => :select, Bands.find(:all,:order =>"title").collect{|band|[band.title, band.id]} | |
end | |
f.buttons | |
end | |
controller do | |
def permitted_params | |
params.permit(:spotlight => [:video, :image, :description]) | |
end | |
end | |
end | |
#Model for spotlight: | |
class Spotlight < ActiveRecord::Base | |
has_attached_file :image, styles: { | |
large: "600x450#", | |
medium: "250x250#", | |
small: "100x100#" | |
}, :default_url => "/images/:style/filler.png" | |
belongs_to :band | |
end | |
#Model for bands: | |
class Bands < ActiveRecord::Base | |
has_attached_file :picture, styles: { | |
large: "600x450#", | |
medium: "250x250#", | |
small: "100x100#" | |
}, :default_url => "/images/:style/filler.png" | |
validates :title, presence: true | |
has_many :spotlight | |
end | |
#Routes file just in case: | |
Oiwbuild::Application.routes.draw do | |
resources :bands, only: [:index, :show] do | |
end | |
resources :spotlight, only: [:index, :show, :new] do | |
end | |
root :to => "home#index" | |
devise_for :admin_users, ActiveAdmin::Devise.config | |
ActiveAdmin.routes(self) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment