2008-02-01から1ヶ月間の記事一覧

条件でのレイアウトの切り替え

layout lambda { |controller| controller.request.mobile? ? 'mobile/forms' : 'forms' } Young risk taker.: [Rails] Mobile on Railsの変更

jpmobile trans_sidが効かないとき

viewで <%= link_to :hoge, {:action => :fuga} %>なときは、 <a href="/xxx/fuga?_sid=098731246hdfa9s8hdf">hoge</a> みたいになるけど名前付きルートで <%= link_to :hoge, fuga_path(@fuga) %>とかのように、名前指定で引数を渡したときだけだと、 def link_to(name, options = {}, html_options = nil) ur…

ARの関連名とか

has_many :hoge_groups, :order => :positionじゃなくて has_many :groups, :class_name => "HogeGroup", :order => :positionでも、おk 命名規約に従うべきかもだけど、xxxxx_xxxxxx_xxxxx_groupsとかウザ過ぎる。

どらぼくえもn

prototype.js使わないで全部にチェックを入れたい

便利に慣らされて脳みそ腐ってた tags = document.getElementsByTagName("input"); for (var i = 0; i < tags.length ; i++) { if(tags[i].type == "checkbox") { tags[i].checked = true; } } prototype.jsありだと $$('input.question_check').each(functi…

grep

grep -r -l 'hogehoge' ./*

rubyのメタプログラミング

参考 http://d.hatena.ne.jp/j-souma/20070612

実行時にvalidatesを追加する

あとづけなvalidatess Hoge.validates_inclusion_of :detail, :in => %w{ 2 3 } fuga= Hoge.new(:foo=> params[:hoge][:foo] ) detail.valid? params[:hoge][:foo]は1だとfalse params[:hoge][:foo]は2だとtrue これ駄目だわ あとのが全部バリデーション効い…

CSV書き出し

report = '' CSV::Writer.generate(report, ',') do |csv| csv << ["ログイン名 ", "パスワード"] User.find_all.each do |model| csv << [model.login, model.password] end end send_data(NKF.nkf('-U -s -Lw', report), :type => 'text/csv; charset=shif…

requestオブジェクト

参考 Rails開発日記 AUTH_TYPE : request.auth_type CONTENT_LENGTH : request.content_length CONTENT_TYPE : request.content_type GATEWAY_INTERFACE : request.gateway_interface PATH_INFO : request.path_info PATH_TRANSLATED : request.path_transla…

2.0でwill_paginateを使う

script/plugin install svn://errtheblog.com/svn/plugins/will_paginate 参考 m(__)m http://brass.to/blog/will_paginate.html AutoPagerizeなwill_paginateにしておく - ザリガニが見ていた...。 will_paginate - happy lie, happy life will_paginate の…

scaffoldとかの本体

gemディレクトリ/rails-2.0.2/lib/rails_generator/generators/components

記法の基本がわかってない

フツーに文字にリンクさせる方法をしらなかった Google グーグル様 ここは絵日記だということをしらなかった おえかきおもれー これは、ハテナハイクについてる機能?ハテナハイクやったことないけど。 なんだ、久しぶりにWEBにふつーに日記でも書いてみたく…

Event.observeに引数

参考 http://d.hatena.ne.jp/n314/20070116/1168936382 http://weblog.metareal.org/2007/09/02/prototype-1-6-0-event-overhaul-release/ http://www.akatsukinishisu.net/itazuragaki/js/bindaseventlistener.html

hじゃないサニタイズ

<%=h @hoge %> だと、けっこう問答無用でエスケープされる。 でも、ある程度のHTMLは入力許したいとき、タグと属性をホワイトリストで指定できた。 <%= sanitize %(<table><tr><td><font id="hoge" style="color:red;">ほげ</font></td></tr></table>), :tags => %w(font), :attributes => %w(class style) %> で表示されるのは <font style="color:red;">ほげ</font> だけ…

date_selectにclassをつけたい

プラグイン作ってその中で module ActionView module Helpers module DateHelper #中略 def select_html(type, html_options, options) case type when "year" then html_class = %(class = "#{options[:yclass] || "date_select"}") when "month" then html…

railsでjavascriptにrubyの値を引数で渡す

<% hoge = "hogehoge" %> <%= javascript_tag(%( window.onload=function default() { alert("#{hoge}"); } )) %>

rails2からはacts_as_*はインストールしないといけない。

ruby script/plugin install acts_as_list

多対多なモデル

class Hoge< ActiveRecord::Base has_many :hoges_fugas_assigns has_many :fugas, :through => :hoges_fugas_assigns, :source => :wawawa_fuga #以下略 class WawawaFuga< ActiveRecord::Base has_many :hoges_fugas_assigns has_many :hoges, :through =>…

route.rbのこと

/admin/hoge/1/fuga/hoo/wawawaとかしたいとき map.namespace :hoge do |hoge| hoge.resources :fuga do |fuga| fuga.resources :hoo, :member=> [:wawawa] end end 参考 http://d.hatena.ne.jp/zariganitosh/20080203/1202091772

rails2.Xでscaffoldで/admin/usersとかのコントローラ作りたいとき

rails2でscaffoldすると、migrateも作られるようになったのはわかった。 で、usersがある状態で/admin/usersみたいな会員管理コントローラを作りたいとき。#いや、管理ページはRestfullにする必要ないかもしれないけど。。/mypage/xxxとかありうると思うから…

認証。acts_as_authenticatedとrole_requirementとopenid_login_generatorで、両対応な感じを目指す。

acts_as_authenticated インスコ→じぇねる→migrate $ ./script/plugin install acts_as_authenticated $ ./script/generate authenticated user account $ rake db:migrateで、おk role_requirement インスコ→じぇねる→migrate $ script/plugin install htt…

VMwareのCentOSのsendmailから外にメールだす

1. /etc/mail/sendmail.mc 中、「DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')」をコメントアウト。http://q.hatena.ne.jp/1179711865 の部分だけまねしたら出て行った。

acts_as_authenticatedとrole_requirementでロール付きの認証。

消えちゃったよ。。 はてなダイアリー素人なので書いたのをなんか間違って消してしまった。。orz 後半だけクリップボードに残ってた。orz なので、書き直した前半は適当。 acts_as_authenticatedをインストール $ ruby script/plugin discover $ ruby script…

mysqlのGRANTやって、ついでにGUIのツールを入れておく

昨日macに入れたmysqlにユーザーを作った。 rootと同じ権限 mysql> GRANT ALL PRIVILEGES ON *.* TO user@"%" -> IDENTIFIED BY 'パスワード' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO user@localhost -> IDENTIFIED BY 'パスワード' WITH…

openid_login_generatorのcontrollerをruby-openidのexampleをみながら直した

一個前の続き。 とりあえず、コントローラーをexampleみながら 直した。とりあえず、これでやってみる。 require "pathname" require "openid" require 'openid/extensions/sreg' require 'openid/extensions/pape' require 'openid/store/filesystem' class…

railsでopenid試してみる。 openid_login_generatorでやってみた。

gem入れる $ gem install ruby-openid $ gem install openid_login_generator $ gem install ruby-yadis $ gem list --local (略) openid_login_generator (0.1) rails (2.0.2) rake (0.8.1) ruby-openid (2.0.3) ruby-yadis (0.3.4) 新しいRailsプロジェク…

leopardにMacPortsをインスコ

mac

ダウンロード http://svn.macosforge.org/repository/macports/downloads/ のdmgをダウンロード インストール 普通にクリックしていく PATHを通す homeディレクトリの.bashrcじゃなくて.bash_profileに export PATH=/opt/local/bin:/opt/local/sbin/:$PATH e…