2008/11/30

[Gmail][Greasemonkey]Gmail Template Switcher を Safari, Google Chrome, Opera でも

Firefox, Safari, Chrome, Opera
Gmail Template Switcher
Gmail Template Switch


複数のアカウントで使用したり、差出人によって署名・挨拶文を変えたい場合に非常に便利なGreasemonkey、Gmail Tempolate Switcher ですが、

しばらく前に、Safariでも利用したいとのコメントをいただき、ようやく Greasekit 上の Safari でも動作を確認しました。


Safari 対応に伴い、Greasemetal での Google Chrome と、Opera でも動作を確認しました。


最新版のダウンロードは、こちらから。


Gmail Template Switcher - v 2.0


なお、ご利用方法は、Gmail にテンプレート切り替え機能を付けてみた - 記憶は削除の方向で をご覧ください。

Update:

Google Chrome Extension 版を作成しました。

2008/11/11

[Rails][Plugins] multimodel-forms プラグインがすごい便利

has_many な関連を、ひとつのフォームで登録したいことはよくありますが、そんなときにおすすめなのが、 multimodel-forms プラグインです。



たとえば、ひとつの記事に複数のコメントの場合は、以下のようになります。



まずは、ベースプロジェクトを作成です。



rails sample
cd sample
ruby script/generate scaffold article title:string body:text
ruby script/generate model comment body:text article_id:integer
rake db:migrate


# ---------- app/models/article.rb ----------
class Article < ActiveRecord::Base
has_many :comments
end


# ---------- app/models/comment.rb ----------
class Comment < ActiveRecord::Base
belongs_to :article
end


multimodel-forms プラグインをインストール




ruby script/plugin install git://github.com/sudothinker/multimodel-forms.git


model を修正


# ---------- app/models/article.rb ----------
class Article < ActiveRecord::Base
has_many_with_attributes :comments
end


view を修正


# ---------- app/views/layouts/articles.html.erb ----------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Articles: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<%= javascript_include_tag :defaults %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>


# ---------- app/views/articles/show.html.erb ----------
<p>
<b>Title:</b>
<%=h @article.title %>
</p>

<p>
<b>Body:</b>
<%= simple_format(h(@article.body)) %>
</p>

<h2>Comments</h2>
<ol>
<% @article.comments.each do |c| %>
<li><%= simple_format(h(c.body)) %> <small>(commented <%= time_ago_in_words(c.created_at) %> ago)</small></li>
<% end %>
</ol>

<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>


# ---------- app/views/articles/new.html.erb ----------
<h1>New article</h1>

<% form_for(@article) do |f| %>
<%= f.error_messages %>

<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit "Create" %>
</p>
<% end %>

<%= link_to 'Back', articles_path %>


# ---------- app/views/articles/edit.html.erb ----------
<h1>Editing article</h1>

<% form_for(@article) do |f| %>
<%= f.error_messages %>

<%= render :partial => 'form', :locals => { :f => f } %>
<p>
<%= f.submit "Update" %>
</p>
<% end %>

<%= link_to 'Show', @article %> |
<%= link_to 'Back', articles_path %>


_form.html.erb を追加


# ---------- app/views/articles/_form.html.erb ----------
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body, :rows => 7 %>
</p>

<h3>Comments</h3>
<div id="comments">
<%= render :partial => 'comments/comment', :collection => @article.comments %>
</div>

<%= add_link "Add Comment", :comment %>


comments/_comment.html.erb を追加


# ---------- app/views/comments/_comment.html.erb ----------
<p class="comment">
<% fields_for_associated :article, comment do |comment_form| %>
<%= comment_form.text_area :body, :rows => 2, :index => nil %>
<%= delete_link_for(comment, "Delete", comment_form) %>
<% end %>
</p>


さっそく動作確認です。




非常に便利な、 multimodel-forms プラグインですが、 acts_as_list をサポートしているので、並び替えも簡単にできるようになります。