Showing posts with label Plugins. Show all posts
Showing posts with label Plugins. Show all posts

Akismet on Ruby on Rails

http://github.com/jfrench/rakismet/tree/master

Recaptcha

http://deadprogrammersociety.blogspot.com/2008/02/recaptcha-on-rails.html

http://recaptcha.net

http://github.com/ambethia/recaptcha/tree/master

Permalink Feature

Just put this method in model (post.rb).

Model
def to_param
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
end

http://www.jroller.com/obie/entry/seo_optimization_of_urls_in


Permalink without ID


Controller
@info = Info.find(params[:id]) # Change the usual find
@info = Info.find_by_nickname(params[:id]) # To look for nickname

Model
def to_param
"#{id}-#{nickname.gsub(/[^a-z0-9]+/i, '-')}" # Change the default
nickname # To display nickname
end

Vote Feature

Terminal
ruby script/generate model Vote

Migration
class CreateVotes < style="font-weight: bold;">Terminal
rake db:migrate

Model
class Info < style="font-weight: bold;">Views/layouts/application.html.erb
<%= javascript_include_tag :defaults %>

Views/show.html.erb

Controller
def vote
@info = Info.find(params[:id])
@user = User.find(session[:user_id])
@info.votes.create(:user => @user)
end

Views/infos/vote.rjs
page.replace_html 'vote_score', "Votes: #{@info.votes.count}"
page[:vote_score].visual_effect :highlight


Vote Once

Controller
def vote
@info = Info.find_by_nickname(params[:id])
@user = User.find(session[:user_id])

if Vote.exists?(@info, @user)
flash[:notice] = 'One vote per user.'
else
@info.votes.create(:user => @user)
end

respond_to do |format|
format.html { redirect_to @info }
format.js
end
end

private
def Vote.exists?(info, user)
not find_by_info_id_and_user_id(info, user).nil?
end

Gedit Plugins

sudo apt-get install gedit-plugins

http://grigio.org/pimp_my_gedit_was_textmate_linux
http://live.gnome.org/Gedit/Plugins

Active Record Random

Installation:
ruby script/plugin install git://github.com/norman/active_record_random.git

Controllers:
@countries = Country.find(:all, :order => :random, :limit => 10)

Controller using will_paginate:
@countries = Country.paginate :page => params[:page], :per_page => 20, :order => :random

Views:
<% for country in @countries %>
<%=h country.name %>
<% end %>

<%= will_paginate @countries %>

http://github.com/norman/active_record_random/tree/master

Thinking Sphinx Tutorial with Delta Indexing

ruby script/plugin install git://github.com/freelancing-god/thinking-sphinx.git
ruby script/plugin install git://github.com/mislav/will_paginate.git # to use will_paginate

In Model
define_index do
indexes searchable_fields, :sortable => true # to sort the fields
set_property :delta => true # no need to run rake ts:index everytime there is a new data entry, but its really recommend to run rake ts:index everyhour or everyday
end

In Controller
def search
@string = Model.search params[:search], :page => params[:page], :per_page => no_of_page, :order => :sortable_fields
end

In View
<% for person in @Person %>
<%= person.name -%> <%= link_to "show", {:action => 'show', :id => person.id} -%>
<% end %>

<%= will_paginate @person %> # to activate pagination

Create boolean delta in model
ruby script/generate migration add_boolean_data

def self.up
add_column :model, :delta, :boolean, :default => false
end

rake db:migrate

Terminal Commands # run this command to activate delta indexing
rake ts:stop # ts or thinking_sphinx
rake ts:index
rake ts:start

Railscasts
Resources

Paperclip Tutorial

script/plugin install git://github.com/thoughtbot/paperclip.git
script/generate paperclip product photo
rake db:migrate

# models/product.rb
has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"

validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']


# views
<%= image_tag @product.photo.url(:small) %>


<% form_for @product, :html => { :multipart => true } do |f| %>
...
<%= f.file_field :photo %>
...
<% end %>


Installation of restful_authentication_tutorial

  • git clone git://github.com/activefx/restful_authentication_tutorial.git
  • cd restful_authentication_tutorial
  • git submodule init
  • git submodule update
  • Set up database.yml file
  • Set up config.yml file (repeat as necessary for test and production environments)
  • settings/domain - should be your domain name without www or http, ex. yourdomain.com
  • settings/in_beta - should be true or false only
  • set new_user_invite_limit to zero to prevent new users from sending invitations when in beta
  • Change the login and password for the admin user in the _set_up_first_admin_user.rb migration
  • Change contact_site method in application.rb to redirect to your site's contact form or info
Install Gem
  • sudo gem install ruby-openid nofxx-annotate rspec rspec-rails yfactorial-utility_scopes rack capistrano
Continue Database Migration
  • rake db:create:all or db:create
  • rake db:migrate