Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
8 total  XML / RSS feed 

configure maven2 tomcat plugin



Install plugin on rails app

script/plugin install [name of plugin, or the url to the desired plugin]

old deprecated legacy plugins repository for Rails

// description of your code here

Find old official rails trunk plugins that didn't make the cut here:

Plugin: Attachment_fu - Install, Setup, Testing

This nightmare has required the following:

- Add
ENV[‘DB’] =mysql’
to /config/environment.rb
- Add:
rescue Technoweenie::AttachmentFu::Backends::S3Backend::RequiredLibraryNotFoundError
to /vendor/plugins/attachment_fu/test/fixtures
- Go into ../test and run: ruby test_helper.rb
- if all goes well you should finish the test_helper load without error.
- delete the file backends/remote/s3_test.rb (useless tests of S3 system)

Attached is a generators directory that should go under the base directory of attachment_fu/
This can be used as a model generator for models using a_fu. Use scaffold_resource generator after attachment_model to generate a skeleton site upon which to build.

Restful Authentication - Check User admin status

Uses h_a_b_t_m relationship to Tier table (via tiers_users join table) to return an array of access groups this user is a member of.

def is_admin? #TODO: make into an accessor?
        return false unless self.tiers
        tier_names = self.tiers.collect {|t|}
        return tier_names.include? "admin"

Acts as Taggable on Steroids: tag cloud rhtml + view helper

// description of your code here
controller layout (base) stylesheet update
  <%= stylesheet_link_tag 'scaffold', 'tag_cloud' %>

create stylesheet, put it in ./public/, name it tag_cloud.css or similar
/* tag_cloud styles*/
.nube1 {font-size: 1.0em;}
.nube2 {font-size: 1.2em;}
.nube3 {font-size: 1.4em;}
.nube4 {font-size: 1.6em;}
.nube5 {font-size: 1.8em;}
.nube6 {font-size: 2.0em;}

partial template call
        TAG CLOUD<br/>
        <%= render(:partial => "shared/article_tag_cloud", :locals => {:tags => @tags}) %>

view template code, as a partial or within index/show action template
        <% # For our purposes, have this filter the list of articles to those with the chosen tag
                tag_cloud true, tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class| %>
                <%= link_to name, tag_path(name), class => css_class # links to Tag resource, with tag name as 'id'
        <% end %>

helper code
        def tag_cloud(active, tags, classes)
                if !active then return end
                max, min = 0, 0
                unless tags.empty?
                        tags.sort! {|x,y| y.count <=> x.count}
                        max = tags.first.count
                        min = tags.last.count                      
                divisor = ((max - min) / classes.size) + 1
                tags.each { |t|
                        yield, classes[(t.count.to_i - min) / divisor]

acts_as_taggable_on_steroids migration

Run this when installing this plugin.

class AddTaggable < ActiveRecord::Migration
  def self.up
    create_table :tags, :force => true do |t|
      t.column :name, :string

    create_table :taggings, :force => true do |t|
      t.column :tag_id, :integer
      t.column :taggable_id, :integer
      t.column :taggable_type, :string
      t.column :created_at, :datetime


  def self.down
    drop_table "tags"
    drop_table "taggings"

Using FlashObject and the miniFLV player to play videos from an entry

Ideally, at some point, I'll modify the plug-in for EE that shows Flash objects to use flashobject.js.

This code assumes custom fields in the blog.


Online Example.

{if project_video}
{if project_video_title}<h4>{project_video_title}: Video Cliph4>{/if}

<div id="videoClip">
<p style="margin: 10px 0; padding: 10px; border: 3px solid red;"><a href="" target="_blank" title="Get Flash Player"><img src="" alt="Get Flash Player" height="31" width="88" align="left" style="padding-right: 10px">a>Flash 7 or above and JavaScript are required to view the project video clip. Please download the //" target="_blank" title="Get Flash Player">latest Flash plug-in.

{if project_video_alt}


« Newer Snippets
Older Snippets »
8 total  XML / RSS feed