ラベル Ruby on Rails の投稿を表示しています。 すべての投稿を表示
ラベル Ruby on Rails の投稿を表示しています。 すべての投稿を表示

2010/03/10

ActiveSalesforce

Salesforce のデータベースに ActiveRecord でアクセスできる ActiveSalesforce アダプタを試した。

公式サイト: ActiveSalesforce
Railsから SalesforceのDBへ簡単にアクセスできるActiveSalesforceを味見してハマったこと を参考にインストール。

lib/active_record/connection_adapters/activesalesforce_adapter.rb の705行目にある,


:dependent => :nullify


を消さないとエラーが発生するので要注意。あと,自分の環境だとRuby 1.8.7を最新版に更新しないと正常に動かなかった。


ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]


Railsのバージョンは 2.1.2 で動作確認できた。Railsの中だけだとつまんないので,ActiveRecordだけで使えないか試してみた。


require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => 'activesalesforce',
:username => 'foo@bar.com',
:password => 'passwordSecurityToken')

class Contact < ActiveRecord::Base
end

Contact.find(:all).each do |c|
io.puts [c.name, c.account.name, c.department, c.title, c.email, c.phone, c.description].join(',')
end

あっさりCSVに顧客情報を吐き出せた。

ODBCドライバも用意されているので,今まで使っていた内製Railsアプリに近いことができそう。

データへのアクセス速度はスゲー遅いけど。

2010/02/07

Redmine 0.9.1 anonymous userからメールによるチケット登録

プロジェクトの設定で"公開(public)"のチェックを外してprivate projectに変更し,管理-ロールと権限Anonymousチケットの追加権限を与える。

Redmineサーバ上でcronにより以下のコマンドを定期的に実行するよう設定すれば,Redmineのユーザのものでないメールアドレスからでもチケットの登録ができた。


rake redmine:email:receive_imap RAILS_ENV="production" host=imap.gmail.com username=foo@bar.co.jp password=xxxxx port=993 ssl=1 project=support tracker=support allow_override=tracker,project allow_anonymous=1 unknown_user=accept no_permission_check=1


メールの受信はGmail(Google Apps)のIMAPで試したが,この場合メールは正常にチケット登録されると未読のままアーカイブされる。うまくチケットが登録されないと受信箱に入ったまま未読になる。

2009/05/06

Rails : Clearance

Ruby on Rail用のplugin, Clearanceをインストールした。

Railsの認証プラグインClearanceを使うに書いてあるとおりにインストールすると,~/.gem以下にインストールされてしまっていたので,Rails Wikiにあるように以下の方法で/usr/local/lib/ruby/gems以下にインストール。

sudo gem install thoughtbot-clearance -s http://gems.github.com

ログアウトさせるには,以下のようなリンクを作成すればよい。

<%= link_to 'Sign out', session_url, :method => :delete %>

Google Group : Clearance : Sign Out link

2009/04/30

Rails 2.3.2 + ActiveScaffold master + file column bridge

Rails 2.3用のActiveScaffoldのインストール

script/plugin install git://github.com/activescaffold/active_scaffold.git -r master

file columnのインストール

script/plugin install http://filecolumn.googlecode.com/svn/tags/file_column

ファイルを添付したいテーブルに例えば file{varchar(255)}というフィールドを追加し、
modelで

class Entry < ActiveRecord::Base
file_column :file, {:fix_file_extensions => nil}
end

というようにそのフィールドを指定すると、ファイルのアップロード後にfileにファイル名が
入力される。

ファイル自体は

public/entry/filename/1

というようにidと関連付けされる。

webrickを起動した際に、以下のようなエラーが発生するので、

uninitialized constant FileColumn::ClassMethods::Inflector

file_columnプラグインでNameError

を参考にfile_column.rbを修正。

Inflector.underscore(self.name).to_s -> self.name.to_s.underscore

2009/03/18

Passenger(mod_rails)を試す

Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用を参考にPassengerをCentOS5にインストールしてみた。

sudo gem install passenger

% sudo passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v2.1.2.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.
1
Checking for required software...

* GNU C++ compiler... found at /usr/bin/g++
* Ruby development headers... found
* OpenSSL support for Ruby... found
* RubyGems... found
* Rake... found at /usr/local/bin/rake
* Apache 2... found at /usr/sbin/httpd
* Apache 2 development headers... not found
* fastthread... found
* Apache Portable Runtime (APR) development headers... not found
* Apache Portable Runtime Utility (APU) development headers... not found

Apacheのヘッダ関連のパッケージがインストールされていないので、httpd-develをインストール。

% sudo yum install httpd-devel

Installed: httpd-devel.i386 0:2.2.3-11.el5_2.centos.4
Dependency Installed: apr-devel.i386 0:1.2.7-11 apr-util-devel.i386 0:1.2.7-7.el5 db4-devel.i386 0:4.3.29-9.fc6 expat-devel.i386 0:1.95.8-8.2.1
Complete!

今度は passenger-install-apache2-module で not found が出なくなった。

/etc/httpd/conf/httpf.conf に以下の3行を追加。

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.1.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.1.2
PassengerRuby /usr/local/bin/ruby

以下の一行も追加すると、development環境でRailsアプリを実行できる。

RailsEnv development

以下のようにVirtualHostの設定を行うと/somewhereにあるRailsアプリを実行できる。


ServerName www.yourhost.com
DocumentRoot /somewhere/public # <-- be sure to point to 'public'!

2008/06/19

Rails: ActiveScaffoldアプリがFirefox3上でエラー発生

こんなエラーが発生。IE7では発生しないので,Firefox3のJavaScriptの実装が原因?

RJS error:

TypeError: $$("#softwares-create--form a.cancel").first().link is undefined

2008/06/11

Strongspaceの安定性が改善されている

ここ2週間ほど使用していなかったStrongspaceに久々にアクセスしてみると,web/sftp/rsyncいずれのプロトコルでもアクセスできないことはなかった。

The Joyent Community: Strongspace Questions and Stuff

Strongspaceの代わりにiTrusteeを使えないか取引先に聞いてみるとfirewallでブロックされるケースが多いので(なぜかStrongspaceはどこの会社からもアクセス可能),10月以降費用が二倍ぐらいになっても構わないから現状レベルのサービスを提供してもらえると助かる。

2008/05/04

Rails 2.0: render_actionはもう使えない

Rails 1.0で使えていた2.0だとエラーになるので、render :action を使うように変更されている。

Rubyist Magazine - Ruby on Rails を使ってみる 第4回 ActionPack

2008/02/16

ActiveRecordのload方法変更

以前から単独でActiveRecordを使うときに、

Warning: require_gem is obsolete. Use gem instead.

という警告が出てたんだけど、エラーではないのでとりあえず放置してた。最近気になってきたので調べると、

require 'rubygems'
require 'active_record'

のようにloadするとよいらしい。
require_gem を gem に変更しただけだと

uninitialized constant ActiveRecord (NameError)

と怒られる。

2007/12/23

Rails: ActiveScaffoldHighlightQuery

検索結果のリストで検索キーワードをハイライトしてくれるプラグイン。

インストール方法:


cd vendor/plugins
svn export \
http://activescaffoldhighlightquery.googlecode.com/svn/trunk/ \
active_scaffold_highlight_query


設定は特にいらない。

ActiveScaffoldHighlightQuery

2007/11/26

ActiveScaffold: list.per_page

ASのリスト表示で1ページに表示するレコード数を設定する。

controllers/application.rb とかに以下のように記述する。

ActiveScaffold.set_defaults do |config|
config.list.per_page = 20
end


config.list.per_page でなくて,config.list.results_per_page と書くとエラーになるので要注意。

ActiveScaffold :: API: List

2007/11/17

ActiveScaffold: Export records to CSV

CSVファイルにデータをexportするための修正点。

ActiveScaffold を使って Ruby on Rails を機能アップする

より引用。
controllerの変更点。

class UsersController < ApplicationController
active_scaffold :user do |conf|
conf.action_links.add 'export_csv', :label => 'Export to Excel', :page => true
end

def export_csv
# find_page is how the List module gets its data. see Actions::List#do_list.
records = find_page().items
return if records.size == 0

# Note this code is very generic. We could move this method and the
# action_link configuration into the ApplicationController and reuse it
# for all our models.
data = ""
cls = records[0].class
data << cls.csv_header << "\r\n"
records.each do |inst|
data << inst.to_csv << "\r\n"
end
send_data data, :type => 'text/csv', :filename => cls.name.pluralize + '.csv'
end
end
モデルの変更点。
class User < ActiveRecord::Base
# The header line lists the attribute names. ID is quoted to work
# around an issue with Excel and CSV files that start with "ID".
def self.csv_header
   "ID,Last Name,First Name, Email, Birthdate"
end
# Emit our attribute values as a line of CSVs
def to_csv
id.to_s << "," << last_name << "," << first_name << "," << email
<< "," << birthdate.to_s
end
end

2007/11/10

active scaffold upload branch

pluginのインストール方法。


./script/plugin install \
http://activescaffold.googlecode.com/svn/branches/upload


vendor/plugins/upload を vendor/plugins/active_scaffold_upload に変更した方がいい。

active scaffold upload branch

File Column Bridge + ActiveScaffold

file_column と ActiveScaffold の橋渡しをする file_column bridge はすでに trunk に取り込まれてるらしい。

http://wiki.activescaffold.com/wiki/published/FileColumnBridge

upload したファイルは、上記の例だと、以下のディレクトリにコピーされる。

public/entry/filename
public/entry/filename/1
public/entry/filename/2
.
.
.

デフォルトの状態だと,Excelのファイルの拡張子が,.xls ではなくて .xls.doc になってしまうので,以下のオプションを model で設定。

file_column :filename, {:fix_file_extensions => nil}

2007/11/06

Userstamp

Model に created_by や updated_by というカラムを設けておいて、レコードの作成/更新時にUser modelのidを自動的に代入できる。

Userstamp

login_engine との親和性も問題ない。
ただし、list 上で #<User:0xb7c88a2c> のように表示されてしまうので、helper で整形する必要あり。ActiveScaffold の場合は partial override を用いる。

2007/11/05

ActiveCalendar

ActiveScafoldにも対応したdate_selectやdatetime_selectをjscalendarに対応させてくれるplugin。

ActiveCalendar - Javascript Calendar on Rails

インストールするには、アプリケーションのルートディレクトリでpluginをインストール。

./script/plugin install http://activecalendar.googlecode.com/svn/trunk/activecalendar

次にlayoutのヘッダ部分に、以下のコードを追加する。これだけ。

<%= stylesheet_link_tag "/javascripts/jscalendar-1.0/calendar-win2k-cold-1.css" %>
<%= javascript_include_tag "jscalendar-1.0/calendar.js" %>
<%= javascript_include_tag "jscalendar-1.0/lang/calendar-en.js" %>
<%= javascript_include_tag "jscalendar-1.0/calendar-setup.js" %>

layout以外のviewの変更や、model, controllerの修正は必要ない。すばらしい。

ActiveUpload+ActiveScaffold

ActiveScaffoldでも使えるファイル・アップロードのためのプラグイン。

ActiveUpload - Easy File Uploads in Rails

IEではうまくuploadはできたけど、Firefoxではうまくできていない。
あと、uploadしたあと、showできていない。

2007/11/04

Rails: LoginEngine

Railsに認証機能を追加するplugin(engine)。

LoginEngineを使ってみる

を参考にインストールして設定を進めていくと、ユーザのテーブルshemaのインポートでコケる。READMEも内容が古くてマチガイだらけ。

config/environmtn.rbに以下の設定を追加。
Rails::Initializer.run do |config|
..中略..
# config.plugins = %W( exception_notification ssl_requirement )
config.plugins = ["engines", "*"]
..中略..
end

require File.join(RAILS_ROOT, "vendor", "plugins", "engines", "lib", "engines", "deprecated_config_support")

module LoginEngine
config :salt, "mysalt"
config :email_from, "foo@company.co.jp"
config :admin_email, "foo@company.co.jp"
config :app_name, "ermgr"
end

#Engine.start :login

Engine.start :login はいらないらしい。
usersテーブルを作成するには、
rake engine_migrate ENGINE=login

でなく、
$ script/generate plugin_migration
create db/migrate
create db/migrate/001_login_engine_to_version_1.rb

を実行する。001_login_engine_to_version_1.rb ができて以下のテーブルが追加される。
plugin_schema_info
schema_info

以下のrakeコマンドを実行すると、
$ rake db:migrate ENGINE=login
(in /home/kaori/ermgr)
== LoginEngineToVersion1: migrating ===========================================
== InitialSchema: migrating ===================================================
-- create_table("users", {:force=>true})
-> 0.1120s
== InitialSchema: migrated (0.1130s) ==========================================

== LoginEngineToVersion1: migrated (0.1780s) ==================================

最終的に users テーブルが追加される。テーブルのcolumnは下図の通り。

Rubyist - pulscope.ruby - Rails 1.2.3でEngines及びLogin Engineプラグインを利用する

が参考になる。