Skip to content

oleriesenberg/acts_as_machinetaggable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActsAsMachineTaggableRedux
===================

Allows for user owned machinetags to be added to multiple classes, and makes machinetags easier to work with.


Prerequisites
=============

Install Edge Rails before you get started so you get RESTful routing.

ActsAsMachineTaggableRedux depends on database tables to store machinetagging information.  Create the migration for these tables with this command:
  
  rake acts_as_machinetaggable:db:create
  
Then run the migration to create the tables with this command:
  
  rake db:migrate
  
Also you will need to add this to your user model:
  acts_as_machinetagger
  
OPTIONAL: The helper functions assume the pressence of a machinetags controller, that is what the machinetag clouds and machinetags will link to.
  
OPTIONAL: To pretty up machinetag clouds and lists you can generate an example stylesheet with this command:

  rake acts_as_machinetaggable:stylesheet:create

and then include this in your layouts that have machinetag clouds:

  <%= stylesheet_link_machinetag 'acts_as_machinetaggable_stylesheet' %>


Example
=======

The following is an example of how you might integrate machinetags with an Item model.

config/routes.rb
  may.resource :items, :machinetags
  
  
app/views/items/new.erb
  <h1>New Item</h1>
  
  <% form_for(:item, @item) do |f| -%>
    
    <%= error_message_for :item %>
    
    <b>MachineTags:</b> <%= f.text_field :machinetag_list -%>
    
    <%= submit_machinetag "Save" -%>
    
  <% end -%>
  
if you want users to own machinetaggings change the machinetags line to this
  <b>MachineTags:</b> <%= f.text_field :machinetag_list, :value => @item.machinetag_list(user) -%>
and add this line beneath it
  <%= f.hidden_field :user_id, :value => user.id -%>
  
app/views/items/show.erb
  Item machinetagged with: 
  <% item.machinetags.each do |machinetag| -%>
    <%= link_to_machinetag(machinetag) %>
  <% end -%>
  
app/views/items/edit.erb
  <h1>New Item</h1>
  
  <% form_for(:item, @item, :html => { :method => :post }) do |f| -%>
  
    <%= error_messages_for :item %>
    
    <b>MachineTags:</b> <%= f.text_field :machinetag_list -%>
    
    <%= submit_machinetag "Save" -%>
  
  <% end -%>


app/controllers/items_controller.rb
  class ItemController < ApplicationController
    def new
      @item = Item.new
    end
    
    def create
      @item = Item.new(params[:item])
      
      respond_to do |format|
        if @item.save
          flash[:notice] = 'Item was successfully created.'
          format.html { redirect_to item_url(@item) }
          format.xml  { head :created, :location => item_url(@item) }
        else
          format.html { render :action => "new" }
          format.xml  { render :xml => @item.errors.to_xml }
        end
      end
    end

    def show
      @item = Item.find(params[:id], :include => :machinetags)
    end
    
    def edit
      @item = Item.find(params[:id])
    end
    
    def update
      @item = Item.find(params[:id])
      
      respond_to do |format|
        if @item.update_attributes(params[:item])
          flash[:notice] = 'Item was successfully updated.'
          format.html { redirect_to item_url(@item) }
          format.xml  { head :updated, :location => item_url(@item) }
        end
          format.html { render :action => "edit"}
          format.xml  { render :xml => @item.errors.to_xml}
      end
    end
  end



MachineTag clouds
==========

MachineTag clouds are created by a helper function, and depend on the counter cache to get fast accurate counts.  To ensure this keeps working properly, don't add new machinetags to a machinetaggable in any way other than using the machinetag.machinetag(machinetaggable) style.  This will ensure that the caches don't lose track.  Also, see the prerequisites for installing the stylesheet so that the machinetag cloud actually looks like a machinetag cloud.  Otherwise, just pop into a view that you want the machinetag cloud to appear and type this:

  <%= machinetag_cloud %>
  
  
  
Copyright (c) 2007 monki(Wesley Beary), released under the MIT license
Copyright (c) 2008 aroedl(Andreas Roedl), released under the MIT license
Copyright (c) 2008 hoodow(Ole Riesenberg), released under the MIT license

About

Fork of acts_as_taggable_redux with the ability to handle machinetags

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Ruby 100.0%