l'essentiel est invisible pour les yeux

Showing posts with label Rails. Show all posts
Showing posts with label Rails. Show all posts

Tuesday, July 15, 2008

[Rails] Gears on Rails helps developers to write fully offline functionnal web applications

Google anounced about Gears on Rails, see Take your Rails application offline with the Gears on Rails project. We can listen to audio interview. This is Rails plugin to manipulate offline data from RoR.We can install GoR as Rails plugin is as follows:


% sudo gem install json_pure
% rails gor_demo && cd gor_demo
% ruby script /plugin install http://gearsonrails.googlecode.com/svn/trunk/acts_as_local


It need to add acts_as_local method in your controller in order to use it.

acts_as_local :except => [:hello]

def create_local
'
post = Post.build(params("post"));
Post.create_local(post);
window.location.reload( false );
'
end


Sorry, I never use GoR yet, but It seems interesting, so i may use it. See Gears on Rails in order to see how to write view and controller for more details.

Tuesday, May 06, 2008

[rails] Running Erubis on Edge Rails

ActionView class was refactoring on Edge Rails, see Ticket #10437 for more details. The template engines are integrated into new ActionView::Template class, but we have to modify some scripts in order to run Erubis on Edge Rails.

0. Install Erubis and Edge Rails

% sudo gem install erubis
% cd /path/to/rails_app/ && rake rails::freeze:edge

1. Create a template handler for Erubis.

Copy and paste below code at #{RAILS_ROOT}/lib/erubis_rails_helper.rb.
require 'erubis'
require 'erubis/preprocessing'

module Erubis
class Eruby
include ErboutEnhancer
end

class FastEruby
include ErboutEnhancer
end
end

module ActionView
module TemplateHandlers
class Erubis < TemplateHandler
include Compilable

# Erubis engine class
cattr_accessor :engine_class
@@engine_class = ::Erubis::Eruby

# Properties
cattr_accessor :init_properties
@@init_properties = {}

# Enable preprocessing if true
cattr_accessor :preprocessing
@@preprocessing = false

def compile(template)
if preprocessing
preprocessor = ::Erubis::PreprocessingEruby.new(template, init_properties)
template = preprocessor.evaluate(@view)
end
engine_class.new(template, init_properties).src
end
end
end
end
ActionView::Template.register_default_template_handler :erb, ActionView::TemplateHandlers::Erubis
ActionView::Template.register_template_handler :rhtml, ActionView::TemplateHandlers::Erubis

2. Configure settings of Erubis in enviroment.rb.

Append below scripts in config/enviroment.rb
require 'erubis_rails_helper'
ActionView::TemplateHandlers::Erubis.engine_class = Erubis::FastEruby
ActionView::TemplateHandlers::Erubis.preprocessing = true
Restart the web server.

Saturday, May 03, 2008

[rails] released jrails_in_place_editing

The jrails_in_place_editing is implementation of inplace editor with jQuery, so this plugin is dependent on jRails. This uses David Hauenstein's jQuery inplace editor plugin. Thank you.

INSTALL (Note: Edge Rails)


./script/plugin install git://github.com/rakuto/jrails_in_place_editing.git

USAGE

# Controller
class BlogController < ApplicationController
in_place_edit_for :post, :title
end

# Customize the action that update the value
class BlogController < ApplicationController
# set_#{object}_#{title}
def set_post_title
post = Post.find(params[:id])
post.title = params[:value]
post.save

# It should render a text
render :text => post.title
end
end

# View
<%= in_place_editor_field :post, :title %>

# Pass some options
<%= in_place_editor_field :post, :title, {}, {:field_type => 'textarea', :textarea_cols => 25, :textarea_rows => 10}%>
<%= in_place_editor_field :post, :title, {}, {:field_type => 'textarea', :textarea_rows => 10}%>

For more details, see jrails_inplace_editing/javascripts/jquery.inplace.js

Tuesday, April 29, 2008

Edge Rails: Describes Gem Dependencies

So far today, Gem dependencies might be written with Capistrano, but we can write Gem dependencies in config/environemt.rb with Edge Rails, and it will be installed with Rake task.

# in config/enviroment.rb


config.gem 'hpricot'
config.gem 'aws/s3', '>= 0.4.0'
config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', :source => "http://code.whytheluckystiff.net"


Install all required Gems.
rake gems:install

Cool