Commit 7f762ca9

mo khan <mo@mokhan.ca>
2013-06-22 04:23:53
change category selection from checkboxes to a dropdown
1 parent 531b4f4
Changed files (3)
app/controllers/creations_controller.rb
@@ -21,7 +21,7 @@ class CreationsController < ApplicationController
 
   def create
     @creation = current_user.creations.create(params[:creation])
-    @creation.category_ids = params[:creation][:category_ids] ||= []
+    @creation.categories << Category.find(params[:category_id])
     current_user.tag(@creation, :with => params[:creation_tags], :on => :tags)
 
     if @creation.save
@@ -35,7 +35,8 @@ class CreationsController < ApplicationController
 
   def update
     @creation = current_user.creations.find(params[:id])
-    @creation.category_ids = params[:creation][:category_ids] ||= []
+    @creation.categories.clear
+    @creation.categories << Category.find(params[:category_id])
     current_user.tag(@creation, :with => params[:creation_tags], :on => :tags)
 
     if @creation.update_attributes(params[:creation])
app/views/creations/_form.html.erb
@@ -35,12 +35,7 @@
     <div class="control-group">
       <label class="control-label">Categories</label>
       <div class="controls">
-        <% for category in Category.all %>
-          <label class="checkbox">
-            <%= check_box_tag "creation[category_ids][]", category.id, @creation.categories.include?(category) %>
-            <%= category.name %>
-          </label>
-        <% end %>
+        <%= select_tag :category_id, options_from_collection_for_select(@categories, "id", "name") %>
         <p class="help-block">
         <strong>Note:</strong> 
         Help us categorize your creation by checking off one or more from the above list.
app/views/creations/show.html.erb
@@ -47,6 +47,15 @@
         <% end %>
       </div>
       <div class="span3">
+
+        <div class="social">
+          <div class="custom-tweet"><a href="https://twitter.com/share?original_referer=<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>&amp;url=&amp;text=<%= yield :product_social %>:%20<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>" onclick="popup(this.href); return false;" class="popup">&nbsp;&nbsp;&nbsp;&nbsp;</a></div>
+          <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
+
+          <div class="fb-like" data-href="<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>" data-send="false" data-layout="button_count" data-width="250" data-show-faces="false"></div>
+          <span class="pin"><a href="//pinterest.com/pin/create/button/?url=<%= "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %>&media=<%= yield :product_image %>&description=<%= yield :product_social %>." data-pin-do="buttonPin" data-pin-config="none"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png"/></a></span>
+        </div>
+
       </div>
     </div>
     <p><%= @creation.story %></p>