Redbox, or a box overlay on rails no comments

Posted by stephane Tue, 20 Mar 2007 18:16:00 GMT

As linked in the last digest, the Craig Ambrose’s Redbox is a Rails plugin inspired by Thickbox. It provides a way to show box overlaying your page.

Example:

Redbox Login
Not fully documented, I’ll give you the way I have used it. Before starting, install the plugin:
script/plugin install http://www.tinboxsoftware.com/plugins/show/redbox/
First you need to verify your CSS and if, same me, your application not cover all the visible page of your navigator you should add the following in your CSS:
html {
  height: 100%;
  width: 100%;
}

body {
  height: 100%;
  width: 100%;
}
This code allows the overlay to cover all the page. Verify also you have the default javascript loaded and add Redbox CSS and javascript:
<%= stylesheet_link_tag 'redbox' %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag 'redbox' %> 
Next you need to create hidden div for each box you need. The name of the div must follow the Redbox convention: hidden_content_actionname_controllername. The default style have to be display: none;.
<div id="hidden_content_login_admin"
 style="display: none;">
Once you have put this code in your layout, you can activate your overlay with the following code (in my case it was a call to an action rendering a piece of html in return):
<%= link_to_remote_redbox <i>'link text'</i>, :url => {:controller => <i>'controllername'</i>, :action => <i>'actionname'</i>} %>

That’s all, Redbox afford other ways to call box don’t hesitate to look at the demos.

When you install redbox, it copies css and javascript to the public folder. You can configure the CSS to modify the transparency of the overlay as you wish.

Hope this article would be helpful

All cheats you ever want to have no comments

Posted by stephane Mon, 19 Mar 2007 14:33:00 GMT

Find on: http://cheat.errtheblog.com/. All ruby’s cheat sheets you ever want, are centralized on this website and dispatched via wiki pages.

Simple, useful, just do :

# installation
$ sudo gem install cheat

# list of the commands
$ cheat cheat

# all the sheets available
$ cheat sheets

Enjoy!

Weekly Rails digest - March 18, 2007 no comments

Posted by stephane Sun, 18 Mar 2007 19:54:00 GMT

Ok, I should have done my home work last week end :). Let’s have a look for what I have found these last few days :

Rails Ajax rating system (Part 1) 1 comment

Posted by stephane Sun, 18 Mar 2007 11:12:00 GMT

Needed for a little project, I found a plugin: “acts_as_rated”.

“Adds rating capabilities to any ActiveRecord object. It has the ability to work with objects that have or don’t special fields to keep a tally of the ratings and number of votes for each object. In addition it will by default use the User model as the rater object and keep the ratings per-user. It can be configured to use another class, or not use a rater at all, just keeping a global rating”

Not yet released as gem please checkout the following trunk : svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated

Installation:

script/plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated

Generate the Rating model:

The rater is User (by default) and rated object is Photo

script/generate migration add_rating
migration/01_add_rating.rb
class AddRating < ActiveRecord::Migration

    def self.up
      ActiveRecord::Base.create_ratings_table
      Photo.add_ratings_columns
    end

    def self.down
      # Remove the added columns
      Photo.remove_ratings_columns
      ActiveRecord::Base.drop_ratings_table
    end

  end
rake db:migrate

Add table ratings and columns rating_count, rating_total, rating_avg to the Photos table.

Usage:

class Photo < ActiveRecord::Base
  acts_as_rated :rating_range => 0..5
end

stephane = User.find_by_username("stephane")
picture = Photo.new("beautiful picture")
picture.rate 4, stephane

that’s all for now … (Next: integrate CSS rating interface)

Older posts: 1 ... 7 8 9 10 11 12