http://rubygems.rubyforge.org/wiki/wiki.pl?RubyGems
wget http://rubyforge.org/frs/download.php/5208/rubygems-0.8.11.zip unzip rubygems-0.8.11.zip cd rubygems-0.8.11 ruby setup.rb
http://rubyforge.org/frs/?group_id=126
wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz tar xzvf cd rubygems-0.9.2 ruby setup.rb
gem install rails --include-dependencies
gem update rails
RubyGems?
cd H:\ruby\rubygems-1.0.1 ruby setup.rb
As of RubyGems 0.8.0, library stubs are no longer needed. Searching $LOAD_PATH for stubs to optionally delete (may take a while)... ...done. No library stubs found. H:\ruby\rubygems-1.0.1>
gem install rails --include-dependencies
Installing ri documentation for rake-0.8.1... Installing ri documentation for activesupport-2.0.2... Installing ri documentation for activerecord-2.0.2...
- c:/ruby/lib/ruby/1.8/i386-mswin32/readline.so (LoadError)
rails demo cd demo ruby script/server
no such file to load -- sqlite3
gem install sqlite3-ruby
http://sqlite.org/download.html
RailsFCGIHandler(NameError)
http://www.ruby-forum.com/topic/56459
gem install fcgi
#RewriteRule ^(.*)$ dispatch.cgi [QSA,L] RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
#RewriteBase /test
execle() failed: No such file or directory
(2)No such file or directory: FastCGI:
dispatch.cgi dispatch.fcgi
#!c:/ruby/bin/ruby
#!/usr/local/bin/ruby
Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration
FastCGI: comm with (dynamic) server "/www/public/dispatch.fcgi" aborted: (first read) idle timeout (30 sec)
ruby script/server
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- gettext/rails (MissingSourceFile)
http://rubyforge.org/frs/?group_id=855
wget http://rubyforge.org/frs/download.php/31658/gettext-1.90.0.gem gem install gettext-1.90.0.gem
Alias /rubytest/ "/webroot/usera/ruby/rubytest/public/" <Directory "/webroot/usera/ruby/rubytest/public"> Options +ExecCGI AllowOverride all Order allow,deny Allow from all AddHandler fastcgi-script .fcgi </Directory>
gem install mongrel --include-dependencies
Select which gem to install for your platform (i686-linux) 1. mongrel 1.1.4 (x86-mswin32-60) 2. mongrel 1.1.4 (java) 3. mongrel 1.1.4 (ruby) 4. mongrel 1.1.3 (ruby) 5. mongrel 1.1.3 (i386-mswin32) 6. mongrel 1.1.3 (java) 7. Skip this gem 8. Cancel installation > 3 Select which gem to install for your platform (i686-linux) 1. fastthread 1.0.1 (mswin32) 2. fastthread 1.0.1 (ruby) 3. Skip this gem 4. Cancel installation > 2
gem install mongrel_cluster
mongrel_rails start -p 8000 -e production -c /webroot/ruby/railstest -d --prefix /railstest
Rails requires RubyGems >= 0.9.4 (you have 0.9.2). Please `gem update --system` and try again.
gem update --system
mongrel_rails stop -P /webroot/ruby/railstest/log/mongrel.pid
ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /railstest http://192.168.1.1:8000/railstest ProxyPassReverse /railstest http://192.168.1.1:8000/railstest
mongrel_rails cluster::configure -N 2 -p 8000 -e production -c /webroot/ruby/railstest -d --prefix /railstest mongrel_rails cluster::start
<Proxy balancer://rails-app/> BalancerMember http://192.168.1.1:8000/railstest loadfactor=10 BalancerMember http://192.168.1.1:8001/railstest loadfactor=10 </Proxy>
Ruby version is not up-to-date; loading cgi_multipart_eof_fix
gem install passenger passenger-install-apache2-module
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby <VirtualHost *:80> ServerName www.yourhost.com DocumentRoot /somewhere/public </VirtualHost>
class CreateProducts < ActiveRecord::Migration def self.up create_table :products do |t| t.column :title, :string, :limit=>100, :null => false t.column :description, :string t.column :image_url, :string, :limit=>200, :null => false t.column :price, :integer, :null => false end end def self.down drop_table :products end end
class AddDateAvailableToProduct < ActiveRecord::Migration def self.up add_column :products,:date_available,:datetime end def self.down remove_column :products,:date_available end end
RAILS_ENV=production db:migrate
development: adapter: mysql database: hoge_development username: hogeuser password: hogepass host: 192.168.1.1 port: 3306 encoding: utf8 timeout: 5000
# ENV['RAILS_ENV'] ||= 'production'
ENV['RAILS_ENV'] ||= 'production'
def self.table_name() "tablename" end
set_table_name "tablename"
product = Product.find(params[:id]) rescue ActiveRecord::RecordNotFound
product = Product.find(params[:id]) rescue => ex flash[:notice] = ex.message
ActiveRecord::Base::transaction() do rascue end
http://underrails.seesaa.net/article/54762314.html
has_many :data1, :class_name => "Data1", :finder_sql => 'select data1.* from data1,data2 where data2.id = data1.koumoku_id and data1.id = #{id}'
has_many :specific_lineitems, :class_name => "lineitem" do def get(id) find :all,:conditions=>['order_id = ?',id] end end
p order.specific_lineitems.get(hoge)
p order.lineitems.find(:first,:conditions =>["order_id=?",hoge])
has_many :lineitems,:include=>"lineitem",:order => "lineitems.cdkoukou"
@table1 = Table1.find_by_sql("select table2koumoku1 from table2")
<% for table1 in @table1 -%> <tr> <td><%= h(table1.table2koumoku1) %></td> </tr> <% end -%>
aaaa = "11" @table1 = Table1.find_by_sql("select table2koumoku1 from table2 where table2koumoku1 = ?",aaaa)
@table1 = Table1.find_by_sql(["select table2koumoku1 from table2 where table2koumoku1 = :id and table2koumoku2 = :id2",{:id => params[:id],:id2 => params[:id2]}])
params = {} params[:para2] = "2" params[:para1] = "1" find(:all,:conditions => ["code_id = :para1 and image_url = :para2",params],:order => "title")
SELECT * FROM `products` WHERE (code_id = '1' and image_url = '2') ORDER BY title
@datas = Table1.connection.select_all("select * from table2")
<% @datas.each{|value| -%> <tr> <td><%= h(value['table2koumoku1']) %></td> </tr> <%} -%>
ActiveRecord?
ActiveHeart?
c:\ruby>gem install gettext ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) getting size of http://gems.rubyforge.org/Marshal.4.8
$KCODE='u' # u=utf s=Shift_JIS, e=EUC-JP require 'jcode'
require 'gettext/rails'
init_gettext "hogedom"
desc "Update pot/po files." task :updatepo do require 'gettext/utils' GetText::ErbParser.init(:extnames => ['.rhtml', '.erb']) GetText.update_pofiles( Dir.glob("{app,config,components,lib}/**/*.{rb,rhtml,rjs,erb}"), end desc "Create mo-files" task :makemo do require 'gettext/utils' GetText.create_mofiles(true, "po", "locale") end
rake updatepo
po/ja/railsproject.po
#: app/models/product.rb:- msgid "Product|Title" msgstr ""
#: app/models/product.rb:- msgid "Product|Title"
rake makemo
def create @code = Code.new(params[:code]) respond_to do |format| if @code.save flash[:notice] = 'Code was successfully created.'
flash[:notice] = 'Code was successfully created.'
flash[:notice] = _('Code was successfully created.')
#: app/controllers/codes_controller.rb:- msgid "Code was successfully created."
<p> <%= f.submit 'Update' %> </p>
<p> <%= f.submit _('Update') %> </p>
msgid "Update"
class Code < ActiveRecord::Base end
<%= debug(params) %>
end end
<html> <head> </head> <body> <% 3.times do |count| %> <%= @test %> <% end %> </body> </html>
undefined method `scaffold' for AdminController:Class
ruby script/plugin install scaffolding ruby script/plugin install http://tools.assembla.com/svn/breakout/breakout/vendor/plugins/classic_pagination/ ruby script/plugin install http://tools.assembla.com/svn/breakout/breakout/vendor/plugins/will_paginate/
ActionController::InvalidAuthenticityToken
skip_before_filter :verify_authenticity_token
ActiveRecord::StatementInvalid in ...
script/generate scaffold book
script/generate scaffold book title:string price:integer
respond_to do |format| format.html # index.html.erb format.xml { render :xml => @books } end
http://wota.jp/ac/?date=20060317#p01
# You can have the root of your site routed with map.root -- just remember to delete public/index.html. # map.root :controller => "welcome"
map.root :controller => "login", :action=>"login"
<%= render(:partial => "cartitem",:collection => @cart.items) %>
<%= cycle(i, "") -%>
validates_uniqueness_of :hoge2,:scope => :hoge1
validates_uniqueness_of :hoge3, :scope => [:hoge1, :hoge2]
ActiveRecord::Validations::ClassMethods
<%= collection_select("user",user.code,@users,"code","name",{:include_blank => true})%>
ApplicationHelper?
def select_ext (strName,strCode,arrData,value,outdata,isBlank) strReturn = '<select id="'+strName+'_'+strCode+'" name="'+strName+'[' + strCode + ']">' if isBlank == true strReturn += '<option value=""></option>' end for oneData in arrData if (strCode == oneData[value]) strReturn += '<option value="'+oneData[value]+'" selected="selected">'+oneData[outdata]+'</option>' else strReturn += '<option value="'+oneData[value]+'">'+oneData[outdata]+'</option>' end end strReturn += "</select>" return strReturn end
codes = Code.find(:all,:order => "id").map {|u| [u.nmname,u.id]} f.select(:code_id,codes,{:include_blank => true})
codes = Code.find(:all,:order => "id") f.collection_select(:code_id,codes,:id,:code,{:include_blank => true})
f.collection_select(:code_id,Code.find(:all,:order => "id"),:id,:code,{:include_blank => true})
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
f.collection_select(:code_id,Code.find(:all,:order => "id"),:id,:code,{:include_blank => true},{"name"=>"hohogee"} )
def update unless params[:aa].nil? p "aa != nil"; end unless params[:aa2].nil? p "aa2 != nil"; end
http://www.fdiary.net/ml/rails/msg/207
<% form_tag(:action => 'update1') do %> <% for @code in @codes %> <%= text_field("code[]", 'nmname') %><br> <% end %> <% end %>
<form action="/codes/update1" method="post"> <input id="code_1_nmname" name="code[1][nmname]" size="30" type="text" value="ddd" /><br> <input id="code_2_nmname" name="code[2][nmname]" size="30" type="text" value="bdddd" /><br> <input id="code_3_nmname" name="code[3][nmname]" size="30" type="text" value="cfffff" /><br> </form>
def update1 #p params unless params[:aa1].nil? params[:code].each{|key,value| Code.update(key,:nmname => value[:nmname]) } end redirect_to :action => 'index' end
params[:code].each{|key,value| Code.update(key,:nmname => value[:nmname]) }
Code.update(params[:code].keys,params[:code].values)
<% form_for :hoge, :url => {:action => 'update1'} do |f| %> <%= f.text_field :nmname %><br> <% for @code in @codes %> <%= text_field("code[]", 'nmname') %><br> <% end %> <% end %>
<form action="/codes/update1" method="post"> <input id="hoge_nmname" name="hoge[nmname]" size="30" type="text" /><br> <input id="code_1_nmname" name="code[1][nmname]" size="30" type="text" value="dddd" /><br> <input id="code_2_nmname" name="code[2][nmname]" size="30" type="text" value="bddddfd" /><br> <input id="code_3_nmname" name="code[3][nmname]" size="30" type="text" value="cfffffa" /><br> </form>
<%= collection_select("code[]", 'code',@codes,:code,:nmname) %>
@pages, @users = paginate(:users, :order_by => 'usercode')
http://wota.jp/ac/?date=20050629
per_page = 5 @tmp = Jikanwari.find_by_sql(["select count(*) as cnt from jikanwari where youbi <> ?","7"]) count = @tmp[0].cnt.to_i @pages = Paginator.new(self, count, per_page, @params['page']) @jkanwaris = Jikanwari.find_by_sql(["select * from jikanwari where youbi <> ? LIMIT ? OFFSET ?", "7", per_page, @pages.current.to_sql[1].to_i])
<%= pagination_links(@pages) %>
<%= form_tag :controller => 'conta',:action => 'touroku' %>
undefined local variable or method `end_form_tag' for #<ActionView::Base:0x4e44aa4>
<%= text_field_tag("koumokumei", atai,options = {:maxlength=>3,:size=>3}) %>
<% for product in @products -%> <%= product.title %><br> <%= text_field_tag :title, product.title %><br> <hr> <% end %>
<form method="post" action="/store/add_to_cart/2?para1=1.0" class="button-to"> <div> <input name="authenticity_token" type="hidden" value="601ad11f3a639c4de81b4c96485842f15ee51f26" /> </div> </form> <hr> <form method="post" action="/store/add_to_cart/1?para1=100.0" class="button-to"> <div> <input name="authenticity_token" type="hidden" value="601ad11f3a639c4de81b4c96485842f15ee51f26" /> </div> </form> <hr>
<%= controller.action_name%>
<%= javascript_include_tag :defaults %>
<script src="/javascripts/prototype.js?1204131898" type="text/javascript"></script>
<% form_tag(:action => 'add_to_cart',:id=>product) do %>
<% form_remote_tag :url=>{:action=>:add_to_cart,:id=>product} do%>
<form action="/store/add_to_cart/3" method="post" onsubmit="new Ajax.Request('/store/add_to_cart/3', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this) + '&authenticity_token=' + encodeURIComponent('da20420b9451c0hohohohohohohoho')}); return false;">
page.replace_html("cartid",:partial=>"cart",:object=>@cart)
gem install ajax_scaffold_generator
<%= javascript_include_tag :defaults %> <div id="hoge"> hoho </div>
<%= javascript_include_tag :defaults %>
<script src="/javascripts/prototype.js?1204131898" type="text/javascript"></script> <script src="/javascripts/effects.js?1204131898" type="text/javascript"></script> <script src="/javascripts/dragdrop.js?1204131898" type="text/javascript"></script> <script src="/javascripts/controls.js?1204131898" type="text/javascript"></script> <script src="/javascripts/application.js?1203128030" type="text/javascript"></script>
page.replace_html("hoge",:partial=>"cart",:object=>@cart)
page.replace_html("hoge",:partial=>"cart",:object=>@cart,:locals=>{:hogepara=>'hogehoge'})
<%= hogepara %>
<div id="hoge"> hoho </div>
<table> <tfoot></tfoot> <tbody id="target"> </tbody> </table>
page['hoge'].update('aaaa').show
page.visual_effect :grow, :tr1, :duration => 0.6
page[:currentitem].visual_effect :highlight,:startcolor => "#88f88",:endcolor => "#114411"
rake db:sessions:create
create db/migrate/XXX_create_sessions.rb
rake db:migrate
# config.action_controller.session_store = :active_record_store
config.action_controller.session_store = :active_record_store
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:478: in `const_missing': uninitialized constant CGI::Session::ActiveRecordStore (NameError) from c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:24: in `const_get' from c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:24:in `session_store='
require 'active_record'
ActionController::InvalidAuthenticityToken in Store#index No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
ActionController?
protect_from_forgery # :secret => '11771fd07d754cc5380bdhohohhhoh'
protect_from_forgery :secret => '11771fd07d754cc5380bdhohohhhoh'
db:sessions:clear
encoding: sjis
$KCODE = 's'
class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_rubytest_session_id' before_filter :set_charset private def set_charset headers["Content-Type"] = "text/html; charset=Shift-JIS" end end
$KCODE = 'SJIS' ActionController::Base.default_charset = 'Shift_JIS'
RUBY_HOME\gems\1.8\gems\activerecord-1.15.3\lib\active_record\validations.rb
@@default_error_messages = { :inclusion => "is not included in the list", :exclusion => "is reserved", :invalid => "is invalid", :confirmation => "doesn't match confirmation", :accepted => "must be accepted", :empty => "can't be empty",
http://wiki.rubyonrails.com/rails/pages/HowToWritePluginToModifyRailsCore
ruby script/generate plugin new_errors
RUBY_HOME\depot\vendor\plugins\new_errors\init.rb
require 'new_errors'
RUBY_HOME\depot\vendor\plugins\new_errors\lib\new_errors.rb
module ActiveRecord class Errors @@default_error_messages[:inclusion] = "is not included in the list ignoramus." @@default_error_messages[:exclusion] = "is reserved. Pay attention!" @@default_error_messages[:confirmation] = "doesn't match confirmation. Pick something that does!" @@default_error_messages[:accepted ] = "must be accepted or it will not work." @@default_error_messages[:wrong_length] = "is the wrong length (should be %d characters). I'm sorry. That is an incorrect response." @@default_error_messages[:taken] = "has already been taken by your mom." end end
new_errors.rb:10: Invalid char `\203' in expression (SyntaxError)
4 errors prohibited this product from being saved There were problems with the following fields:
http://jp.rubyist.net/magazine/?0012-RubyOnRails
class Product < ActiveRecord::Base
column.human_name
Product.human_attribute_name(column.human_name)
def human_attribute_name(attribute_key_name) if @field_names && @field_names[attribute_key_name] @field_names[attribute_key_name] else _human_attribute_name(attribute_key_name) end end
_human_attribute_name(attribute_key_name)
Product.human_attribute_name(column.name)
<%= render :partial => 'form' %>
<%= Product.human_attribute_name("title") %>
Loading test environment (Rails 2.0.2) >> "book".pluralize "book".pluralize => "books" >> "books".singularize "books".singularize => "book"
yamlfile = YAML::load(File.open('hoge.yml'))
disable_with
Status: 500 Internal Server Error Mongrel timed out this thread: shutdown
[Wed Apr 01 10:24:03 2008] [error] [client 192.168.1.1] proxy: error reading status line from remote server 127.0.0.1 [Wed Apr 01 10:24:03 2008] [error] [client 192.168.1.1] proxy: Error reading from remote server returned by /hoge
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@verification_timeout = 0
ActiveRecord::Base.verification_timeout = 14400
show variables;
[mysqld] wait_timeout=31536000 interactive_timeout=31536000
gem install mysql
ERROR: Error installing mysql: ERROR: Failed to build gem native extension.
gem install mysql -- --with-mysql-dir=/usr/local/mysql
Lost connection to MySQL server during query
api
ActiveRecord
ajax_scaffold_generator
pagination
AvailableGenerators
Rails Plugins...