離婚したよ\(^o^)/

Standard
離婚したよ\(^o^)/

巨乳が好きとかを通り越して最近はもういっそ巨乳になりたいと思う。
 
 
携帯の位置情報を使ったWebサービスを作ってみたいと思って、もとい、流行りに乗っかりたいと思って、ここは久々にRailsでしょうと思ってやったら驚くほど色々忘れててビビったのである。。あととりあえずherokuで動かせばいいでしょーって思ってたけど、なんかアプリ作るとno service name (Socket Error)とかでまくってアジャイルさをすっかり奪われてお尻が痛くなったのである。CORESERVERにrubyいれようかと思ったけど勉強用のサーバがあってもいいかと思ったので安いサーバ借りたのである。借りたのはrailsplaygroundの月5$プラン。容量3GBでFast CGIでRails動かせるらしいのである。9$プランだとmongrel動くそうですのである。
 
RailsをCGIで動かしたことなかったし、.htaccessの書き方とかよくわからんし、無駄に時間かかったので復習メモ。railsplayground環境で携帯位置情報とUIDをDBにつっこむだけのアプリを作るとこまで。ちなみにアプリは1つだけでメインのドメイン(http://xxx.railsplayground.net/とか)にアクセスして動かす。
 
 
DBつくる
 
とりあえずデータベースを作る。MySQLかPostgreSQLはデフォルトで使える。railsplaygroundのコントロールパネルはcPanelっていうかなりGUI度高い管理画面でビックリした。cPanelから[データベース] → [MySQLデータベースウィザード] を起動して従えばOK。なぜかデータベース名に16文字っていう制限がある。しかも”ユーザ名_”が頭につくから”xxx_production”とかそもそも入れれない。気にせず適当な名前をつけとけばええのである。データベースとユーザを追加したら、cPanel、略してシーパネから[データベース] → [phpmyadmin]起動。データベースの追加を確認して、[新DB] → [操作]から照合順序を確認する。自分のはデフォルトでlatin1_swedish_ciとかになってたので、utf8_general_ciとかに変えとく。
 
 
Railsアプリ作成
 
wikiがあるので従う。
 

  • ssh yourdomain.net
  • rails railsapp –with-dispatcher
  • mv public_html public_html_bak
  • ln -s ~/railsapp/public ~/public_html

 
“–with-dispatcher”をつけるとrailsapp/publicの下にdispatch.cgiとかを作ってくれるので、public_htmlをそこのシンボリックリンクに変えるって魂胆である。この時点で”http://yourdomain.net/”にアクセスしていつものRailsのindex.htmlが見れることを確認。
 
 
.htaccess追加
 
新しいRailsは.htaccessファイルを作ってくれないので自分で作る。railsapp/public配下に↓の内容で.htaccessファイルを作る。
 

# General Apache options
Options +FollowSymLinks +ExecCGI
# AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" 

 
RailsのREADMEからコピペ。3行めの”AddHandler fastcgi-script .fcgi”だけコメントアウトする。これでrailsアプリURLへのアクセスがFast CGIで動くようになっているはずである。のである。
 
 
アプリを作る
 
まずはjpmobileをrailsapp/vendor/plugins/配下に配置。githubからcloneしてSFTPかなんかであげればよい。
 
 
railsapp/controllers/tetete_controller.rb

class TeteteController < ApplicationController
  def index
    unless request.mobile?
      render :action => 'pc_index'
    else
      @pos = request.mobile.position
      @ident = request.mobile.ident
      if @pos
        @c_lon = @pos.lon #緯度
        @c_lat = @pos.lat #経度
      end
    end
  end

  def create
    @cloud = Cloud.new(params[:cloud])
    if @cloud.save
      @lists = Cloud.find :all
      render :action => 'list'
    end
  end

  def list
    
  end

  def pc_index
    
  end

end

 
 
railsapp/models/cloud.rb

class Cloud < ActiveRecord::Base
end

 
 
railsapp/views/tetete/index.html.erb

<h1>tetete.cloud</h1>
<% form_for :cloud, @cloud, :url => { :action => "create" } do |f| %>
<table>
  <tr>
    <td>Where is here?:<br/><%= get_position_link_to %></td>
  </tr>
  <tr>
    <th>Name</th>
  </tr>
  <tr>
    <td><%= f.text_field :name, :size => 10 %></td>
  </tr>
  <tr>
    <th>Description</th>
  </tr>
  <tr>
    <td><%= f.text_area :description, :cols => 20, :rows => 10 %></td>
  </tr>
    
<% if @pos %>
  <tr>
    <td><%= f.text_field :lat, :value=>@c_lat %></td>
  </tr>
  <tr>
    <td><%= f.text_field :lon, :value=>@c_lon %></td>
  </tr>
<% end %>
<% if @ident %>
  <td><%= f.text_field :mid, :value=>@ident %></td>
<% end %>
  <tr>
    <td colspan="2"><%= submit_tag 'Create' %></td>
  </tr>
<% end %>
</table>

 
 
railsapp/views/tetete/list.html.erb

<h1>tetete.cloud</h1>
<table>
<% @lists.each do |list| %>
  <tr>
    <td colspan="2"><%=h list.name %></td>
    <td colspan="2"><%=h list.description %></td>
    <td><%=h list.lat %></td>
    <td><%=h list.lon %></td>
  </tr>
<% end %>
</table>

 
 
railsapp/views/tetete/pc_index.html.erb

<%#
# To change this template, choose Tools | Templates
# and open the template in the editor.
%>

<%= "pc_index.html" %>

 
 
railsapp/config/environment.rb

ENV['RAILS_ENV'] ||= 'production'

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install
  # config.gem "bj"
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
  # config.gem "aws-s3", :lib => "aws/s3"

  # Only load the plugins named here, in the order given (default is alphabetical).
  # :all can be used as a placeholder for all plugins not explicitly named
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  # Run "rake -D time" for a list of tasks for finding time zone names.
  config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
  # config.i18n.default_locale = :de
end

 
 
railsapp/config/routes.rb

ActionController::Routing::Routes.draw do |map|
  map.resources :tetete

  # The priority is based upon order of creation: first created -> highest priority.

  # Sample of regular route:
  #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   map.resources :products

  # Sample resource route with options:
  #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

  # Sample resource route with sub-resources:
  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
  
  # Sample resource route with more complex sub-resources
  #   map.resources :products do |products|
  #     products.resources :comments
  #     products.resources :sales, :collection => { :recent => :get }
  #   end

  # Sample resource route within a namespace:
  #   map.namespace :admin do |admin|
  #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
  #     admin.resources :products
  #   end

  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
  map.root :controller => "tetete"

  # See how all your routes lay out with "rake routes"

  # Install the default routes as the lowest priority.
  # Note: These default routes make all actions in every controller accessible via GET requests. You should
  # consider removing or commenting them out if you're using named routes and resources.
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

 
 
railsapp/config/database.yml

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql
# On Mac OS X:
#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
# On Mac OS X Leopard:
#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
#       This sets the ARCHFLAGS environment variable to your native architecture
# On Windows:
#   gem install mysql
#       Choose the win32 build.
#       Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: mysql
  encoding: utf8
  database: yourname_xxx
  pool: 5
  username: yourname_xxx
  password: xxxxxxxxxx
  socket: /tmp/mysql.sock

 
 
railsapp/db/migrate/xxxxxx.rb

class CreateClouds < ActiveRecord::Migration
  def self.up
    create_table :clouds do |t|
      t.string :name
      t.text :description
      t.decimal :lon, :precision => 17, :scale => 14, :default => 0.0
      t.decimal :lat, :precision => 17, :scale => 14, :default => 0.0
      t.string :mid
      t.timestamps
    end
  end

  def self.down
    drop_table :clouds
  end
end

 
 
index.html削除

  • rm railsapp/public/index.html

 
 
migrate

  • rake db:migrate RAILS_ENV=production

 
 
んで、携帯でhttp://yourdomain.net/にアクセスすればなんか出てくるはず。japmobile最高っすね!
 
ファイルを修正したときは一回Fast CGIのプロセスをkillしないと反映されないのであるうううう。
 

  • ps ux | grep fcgi
  • kill -9 「ruby が起動したfcgiのPID」

 
 
合コンしたいうわうわー
 
 
 

Cover image is not found
amazon.co.jpで詳細情報を見る