Commit 2a75c93

mo khan <mo@mokhan.ca>
2013-06-23 04:26:12
load tags from controller
1 parent 21120af
Changed files (2)
app
app/controllers/needs_controller.rb
@@ -2,6 +2,7 @@ class NeedsController < ApplicationController
   before_filter :authenticate_user!, :except => [:index, :show]
   def index
     @needs = Need.all
+    @tags = ActsAsTaggableOn::Tag.pluck(:name)
   end
 
   def show
@@ -17,9 +18,9 @@ class NeedsController < ApplicationController
     location = GeoLocationService.GetGeoLocation(params[:location]) if params[:location]
     current_user.tag(@need, :with => params[:need_tags], :on => :tags)
     if @need.save
-       redirect_to needs_path, notice: 'Need was successfully created.'
+      redirect_to needs_path, notice: 'Need was successfully created.'
     else
-       render action: "new"
+      render action: "new"
     end
   end
 end
app/views/needs/index.html.erb
@@ -1,8 +1,7 @@
 <% content_for :javascript do %>
 <script type="text/javascript" charset="utf-8">
 $(function() {
-  var all_tags = [ <% ActsAsTaggableOn::Tag.pluck(:name).each { |item| %> '<%= item %>', <% } %> ];
-  $('#tags').tagit({ availableTags: all_tags }); 
+  $('#tags').tagit({ availableTags: [<% @tags.each { |x| %>'<%= x %>',<% } %>] });
 });
 </script>
 <% end %>