Adding attr_accessors and paperclip file uploads

This commit is contained in:
Will Marshall
2014-05-16 16:30:37 +10:00
parent 0958602418
commit 61cf35a5b9
4 changed files with 34 additions and 6 deletions

View File

@@ -15,12 +15,10 @@ module Admin
redirect_to main_app.admin_enterprise_groups_path
end
private
def collection
EnterpriseGroup.by_position
end
end
end

View File

@@ -4,10 +4,12 @@ class EnterpriseGroup < ActiveRecord::Base
has_and_belongs_to_many :enterprises
validates :name, presence: true
#validates :description, presence: true
validates :description, presence: true
attr_accessible :name, :description, :long_description, :on_front_page, :enterprise_ids
attr_accessible :promo_image
has_attached_file :promo_image, styles: {medium: "1200x1200>"}
has_attached_file :promo_image, styles: {medium: "800>400"}
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
attr_accessible :logo

View File

@@ -3,6 +3,16 @@
%br/
= f.text_field :name
= f.field_container :description do
= f.label :description
%br/
= f.text_field :description
= f.field_container :long_description do
= f.label :long_description
%br/
= f.text_area :long_description
= f.field_container :on_front_page do
= f.label :on_front_page, 'On front page?'
%br/
@@ -12,3 +22,22 @@
= f.label :enterprise_ids, 'Enterprises'
%br/
= f.collection_select :enterprise_ids, Enterprise.all, :id, :name, {}, {class: "select2 fullwidth", multiple: true}
.row
.alpha.three.columns
= f.label :logo, class: 'with-tip', 'data-powertip' => 'This is the logo'
.with-tip{'data-powertip' => 'This is the logo'}
%a What's this?
.omega.eight.columns
= image_tag @object.logo.url if @object.logo.present?
= f.file_field :logo
.row
.alpha.three.columns
= f.label :promo_image, class: 'with-tip', 'data-powertip' => 'This image is displayed at the top of the Group profile'
.with-tip{'data-powertip' => 'This image is displayed at the top of the Group profile'}
%a What's this?
.omega.eight.columns
= image_tag @object.promo_image.url if @object.promo_image.present?
= f.file_field :promo_image

View File

@@ -62,9 +62,9 @@ feature %q{
page.should have_select 'enterprise_group_enterprise_ids', selected: [e1.name, e2.name]
fill_in 'enterprise_group_name', with: 'xyzzy'
fill_in 'enterprise_group_description', with: 'This is a description'
uncheck 'enterprise_group_on_front_page'
unselect e1.name, from: 'enterprise_group_enterprise_ids'
select e2.name, from: 'enterprise_group_enterprise_ids'
click_button 'Update'
@@ -72,7 +72,6 @@ feature %q{
eg = EnterpriseGroup.last
eg.name.should == 'xyzzy'
eg.description.should == 'This is a description'
eg.on_front_page.should be_false
eg.enterprises.should == [e2]
end