Commit 2389fbea
Changed files (3)
app
models
views
registrations
db
app/models/user.rb
@@ -13,7 +13,7 @@ class User < ActiveRecord::Base
validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true
#validates_with UrlValidation
has_many :authentications
- has_many :interests
+ has_and_belongs_to_many :interests, :join_table => 'users_interests', :uniq => true, :autosave => true
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
attr_accessible :name, :email, :website, :twitter, :facebook, :password, :password_confirmation, :remember_me
has_many :creations, :dependent => :destroy
app/views/registrations/edit.html.erb
@@ -54,6 +54,14 @@
<%= f.label :facebook, :class => "control-label" %>
<div class="controls"> <%= f.text_field :facebook, :class => "input-xlarge", :placeholder => "http://www.facebook.com/your_profile", :maxlength => "255" %> </div>
</div><!-- /control-group -->
+ <div class="control-group">
+ <% for interest in Interest.all %>
+ <label class="checkbox">
+ <%= check_box_tag "user[interest_ids][]", interest.id, current_user.interests.include?(interest) %>
+ <%= interest.name %>
+ </label>
+ <% end %>
+ </div><!-- /control-group -->
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Save changes" />
<button type="reset" class="btn">Cancel</button>
db/seeds.rb
@@ -5,14 +5,21 @@
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
-Category.create(:name => 'Fondant', :slug => 'fondant')
-Category.create(:name => 'Butter Cream', :slug => 'butter-cream')
-Category.create(:name => 'Cup Cake', :slug => 'cup-cake')
-Category.create(:name => 'Tiered', :slug => 'tiered')
-Category.create(:name => '3D', :slug => '3d')
-Category.create(:name => 'Birthday', :slug => 'birthday')
-Category.create(:name => 'Wedding', :slug => 'wedding')
-Category.create(:name => 'Holiday', :slug => 'holiday')
-Category.create(:name => 'Theme', :slug => 'theme')
-Category.create(:name => 'Anniversary', :slug => 'anniversary')
-Category.create(:name => 'Baby Shower', :slug => 'baby-shower')
+unless Category.any?
+ Category.create(:name => 'Fondant', :slug => 'fondant')
+ Category.create(:name => 'Butter Cream', :slug => 'butter-cream')
+ Category.create(:name => 'Cup Cake', :slug => 'cup-cake')
+ Category.create(:name => 'Tiered', :slug => 'tiered')
+ Category.create(:name => '3D', :slug => '3d')
+ Category.create(:name => 'Birthday', :slug => 'birthday')
+ Category.create(:name => 'Wedding', :slug => 'wedding')
+ Category.create(:name => 'Holiday', :slug => 'holiday')
+ Category.create(:name => 'Theme', :slug => 'theme')
+ Category.create(:name => 'Anniversary', :slug => 'anniversary')
+ Category.create(:name => 'Baby Shower', :slug => 'baby-shower')
+end
+unless Interest.any?
+ Interest.create(:name => 'Hobbyist')
+ Interest.create(:name => 'Professional')
+ Interest.create(:name => 'Home Based Business')
+end