{"id":16809088,"url":"https://github.com/timakin/apper","last_synced_at":"2025-03-17T09:43:59.464Z","repository":{"id":7896699,"uuid":"9276082","full_name":"timakin/apper","owner":"timakin","description":"apper","archived":false,"fork":false,"pushed_at":"2014-12-25T16:54:35.000Z","size":1916,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T19:19:49.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timakin.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-07T12:15:16.000Z","updated_at":"2014-03-23T16:37:46.000Z","dependencies_parsed_at":"2022-08-20T05:10:26.884Z","dependency_job_id":null,"html_url":"https://github.com/timakin/apper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timakin","download_url":"https://codeload.github.com/timakin/apper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244012814,"owners_count":20383667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T10:00:47.108Z","updated_at":"2025-03-17T09:43:59.435Z","avatar_url":"https://github.com/timakin.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= 前提条件\nUserテーブル=\u003eDevise\nItemテーブル=\u003e記事を作成する。title:string text:textでscaffold\n\n\n= CarrerWave File Uploading  \nASCIICASTS[http://ja.asciicasts.com/episodes/253-carrierwave-file-uploads]\nほぼまんまでいけるimageカラムをitemテーブルに追加。\n\n= Devise 導入\nこれ[http://kitbc.s41.xrea.com/main/?use_devise]にそってやる。\n\n= リレーション\nitemモデルに参照元となるuser_idを追加（これ忘れたら作れない。案外これ載っていない。）\n  rails g migration add_user_id_to_items\n\nそのあとフォームを利用してuser_idを自動で登録するようにする。\n  \u003cdiv class=\"field\"\u003e\n    \u003c%= f.hidden_field :user_id, :value =\u003e current_user.id %\u003e  \n  \u003c/div\u003e\n\nこちら[http://neec-is.g.hatena.ne.jp/is178/20091206/1260069121]を見て、試しにEmailアドレスを表示する。\n  \u003ctd\u003e\u003c%= item.user.email %\u003e\u003c/td\u003e\n\nこれをindex.html.erbに追加。\nUserテーブルにnameでも追加すれば、簡単に表示ができる。\n\n= Mini_magickでページごとに画像調整\n\nRailsGirls[http://railsgirls-jp.github.io/thumbnails/]に載っている。\n\nMini_magick該当箇所のコメントアウトを外す\n\napp/uploaders/image_uploader.rb\n\n  version :thumb do\n    process :resize_to_fill =\u003e [200,200]\n  end\n\n  version :show do\n    process :resize_to_fill =\u003e [300,250]\n  end\n\nのように、versionごとに分けて記載する。\n\nそのあと、viewのitemでthumbならindexのimage_tagの末尾に(:thumb)をつけるなど、各場合についてversionを適用する。\n\n= acts_as_taggable_on\n\nASCIICASTS[http://railscasts.com/episodes/382-tagging?language=ja\u0026view=asciicast]\nをまんま使えば大丈夫。\nmapはタイトル検索などで使い分けないといけないかも\n\n= bootstrap\n\napplication.js,application.cssにrequireを書く\nnavbarはnavbar-fixed-topにすると、ウィンドウを小さくしても\n余白が生まれたりしない。\n\nroot_pathやdestroy_user_session_pathなどは、liタグの次に書く\n\n  \u003c% if user_signed_in? %\u003e\n    ...\n  \u003c% end %\u003e\n\nでnavbarの表示を変える\n\nflat-uiとかも適用できる！やったね！\n\n= サムネイルにリンクはる\n\nこちら[http://d.hatena.ne.jp/satake7/20080908/p1]を参考にする\n\n= 投稿したユーザーのみdestroyとかeditとか表示する\n\n  \u003c% if current_user == item.user %\u003e\n    ...\n  \u003c% end %\u003e\n\nitemってとこが重要。\nこのやり方で他のページもできるよ。\n\n= created_atが新しい順に表示する\n\nこちら[https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-talk/gANZDdb8u5s]を参考にする。\n例えば\n\n  if params[:tag]\n    @items = Item.tagged_with(params[:tag])\n    @items = @items.sort_by{ |m| m.created_at}.reverse()\n  else\n    @items = Item.all\n    @items = @items.sort_by{ |m| m.created_at}.reverse()\n  end\n\nindexならこんな感じ\n\n= party_boyでフォロー機能\n\n微妙に難しかった\nこちら[http://tnakamura.hatenablog.com/entry/20120703/party_boy]\n\n  rails generate party_boy\n\nマイグレーションファイルの名前のせいでエラーが出るから\n\n  class CreateRelationship\n    ...\n  end\n\nにする。詳細はこちら[https://github.com/mnelson/party_boy/issues/6]\nこれを修正したら、\n\n  rake db:migrate\n\nこうしてリレーションに必要なテーブルが作成される。\nけど、アクセスできない変数があるので、relationshipモデルに\n\n  attr_accessible :requestor, :requestee, :restricted\n\nと記載する。こうする事でほぼ使えるようになる。\nこっからが面倒。まずUserモデルに\n\n  acts_as_followable\n\nを追加。\nその後コントローラー、ルーティング、ビューの順に編集していく。\nまずコントローラー。フォロー追加、解除のアクションを追加する。\n\n  def user_follow\n    @item = Item.find(params[:id])\n    current_user.follow(@item.user)\n    # これはscaffoldのやつと同じで、item_urlにリダイレクトするようになっている。\n    respond_to do |format|\n      format.html { redirect_to item_url }\n      format.json { head :no_content }\n    end\n  end\n\n  def user_unfollow\n    @item = Item.find(params[:id])\n    current_user.unfollow(@item.user)\n    respond_to do |format|\n      format.html { redirect_to item_url }\n      format.json { head :no_content }\n    end\n  end\n\n次にルーティング。アクションがあったときのpathをitemsのルートに追加する。\n\n  resources :items do\n    member do\n      get \"user_follow\"\n      get \"user_unfollow\"\n    end\n  end\n\n最後にビュー。これが鬼門だった……ルーティングを確認してから、以下を追加した。\n\n  \u003c% unless current_user==@item.user %\u003e\n    \u003c% if current_user.following?(@item.user) %\u003e\n      \u003c%= link_to \"Remove\", user_unfollow_item_path %\u003e\n    \u003c% else %\u003e\n      \u003c%= link_to \"Add Friend\", user_follow_item_path %\u003e\n    \u003c% end %\u003e\n  \u003c% end %\u003e\n\nこれでおっけー。ついでにフォロワーを表示するには、\n\n  @following = current_user.following\n\nをコントローラーに追加した後、ビューに以下を追加すれば良い。\n\n  \u003cp\u003e\n    \u003c% @following.each do |f| %\u003e\n    \u003cb\u003e\u003c%= f.email %\u003e\u003c/b\u003e\u003cbr /\u003e\n    \u003c% end %\u003e\n  \u003c/p\u003e\n\n= sextant\n\nもうrake routesなんていらない。Rail4.0だと標準装備らしい。3.2でも見れる。便利でいいね。\n\n= ログイン、ログアウトの表示を変更する\n\nまあ簡単\n\n  \u003c% if user_signed_in? %\u003e\n  \u003cul class=\"nav pull-right\"\u003e\n    \u003cli class=\"dropdown\"\u003e\n      \u003ca href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\"\u003e\n      \u003c%= current_user.email %\u003e\n      \u003cspan class=\"caret\"\u003e\u003c/span\u003e\n      \u003c/a\u003e\n      \u003cul class=\"dropdown-menu\"\u003e\n       \u003cli\u003e\u003ca href=\"\"\u003eGoogle+に参加\u003c/a\u003e\u003c/li\u003e\n       \u003cli\u003e\u003c%= link_to \"ログアウト\", destroy_user_session_path, method: :delete %\u003e\u003c/li\u003e\n       \u003cli\u003e\u003ca href=\"\"\u003eアカウント設定\u003c/a\u003e\u003c/li\u003e\n       \u003cli class=\"divider\"\u003e\u003c/li\u003e\n       \u003cli\u003e\u003c%= link_to \"ログアウト\", destroy_user_session_path, method: :delete %\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n  \u003c/ul\u003e\n  \u003c% else %\u003e\n    \u003cul class=\"nav pull-right\"\u003e\n    \u003cli class=\"dropdown\"\u003e\n    \u003ca href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\"\u003e\n    test\n    \u003cspan class=\"caret\"\u003e\u003c/span\u003e\n    \u003c/a\u003e\n    \u003cul class=\"dropdown-menu\"\u003e\n    \u003cli\u003e\u003ca href=\"\"\u003eGoogle+に参加\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"\"\u003eプライバシー\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"\"\u003eアカウント設定\u003c/a\u003e\u003c/li\u003e\n    \u003cli class=\"divider\"\u003e\u003c/li\u003e\n    \u003cli\u003e\u003c%= link_to \"ログイン\", new_user_session_path %\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c% end %\u003e\n\n\n= Ransack\n\n目が飛ぶくらい簡単\nこちら[http://railscasts.com/episodes/370-ransack?language=ja\u0026view=asciicast]を参考に！\nitems_controllerのindexに書く。\n（今回はtagとの兼用の仕方がわからないので、とりあえずtagの機能をコメントアウト）\n\n  #if params[:q][:tag]\n  #  @items = Item.tagged_with(params[:q][:tag])\n  #  @items = @items.sort_by{ |m| m.created_at}.reverse()\n  #else\n\n  @search=Item.search(params[:q])\n  @items=@search.result\n  @items = @items.sort_by{ |m| m.created_at}.reverse()\n\n  #end\n\nindexには検索フォームを作る\n\n  \u003c%= search_form_for @search do |f| %\u003e\n    \u003cdiv class=\"field\"\u003e\n      \u003c%= f.label :title_cont, \"Title\" %\u003e\n      \u003c%= f.text_field :title_cont %\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"actions\"\u003e\u003c%= f.submit \"Search\" %\u003e\u003c/div\u003e\n  \u003c% end %\u003e\n\n\n= acts_as_commentable\n\nコメント機能をつける。今回はacts_as_commentableを使う。\nこちら[http://yorunocafe.blogspot.jp/2011/08/railsactsascommentable.html]を参照\n\n  rails g comment\n\nを忘れないように。今回はuser_idもリレーションのために追加しておいた。\n\nなんかCommentsControllerにしなくちゃいけなかったり、命名規則の部分でミスが多いから、\n自分で直すように気をつけないといけない。\nあとコメントを表示するモデルの名前をpostから置き換えないと表示できないので注意。\nあと、_formと_showの二つを作ってファイルを分割した。\nまじで命名規則にそってない解説だから注意。\n\nuserモデルとcommentモデルにリレーションを設定すれば、\ncommentを作成したuserの名前やメールアドレスも表示できる。\nただ、この設定をする以前にuser_idを持たないcommentを作成していると、エラーが出るので注意。\n\n= Public_Activity\n\nこちら〜[http://railscasts.com/episodes/406-public-activity?view=asciicast]\nでもこのscreencastには、/app/config/activities_controller.rbとなっていたり（/app/controller/activities_controller.rbがほんと）、\n\n  class ActivitiesController \u003c ApplicationController\n    def index\n      @activities = PublicActivity::Activity.order('created_ad DESC')\n    end\n  end\n\nが書かれていなかったり……\nこれはdefault_scopeのオプションを参考にして、修正できた。うれしい(´；д；｀)\ncurrent_userがからんでくると絶対エラーが出る！\nこの野郎と思ったけど、/app/model/comment.rbには\n\n  include PublicActivity::Model\n  tracked owner: -\u003e(controller, model) { controller \u0026\u0026 controller.current_user }\n\nを追記。ちゃんとpublic_activityのmodelをincludesなきゃいけない。\nあと、current_userについての記述は基本無視していい。\n最終的にviewはこんな感じになった。\n\n  \u003ch1\u003eActivities#index\u003c/h1\u003e\n    \u003c% @activities.each do |activity| %\u003e\n      \u003cdiv class=\"activity\"\u003e\n    \u003c% if activity.trackable_type == \"Item\" %\u003e\n      \u003c%= activity.owner.email if activity.owner %\u003e made \u003c%= link_to activity.trackable.title, activity.trackable %\u003e \n    \u003c% else %\u003e\n      \u003c%= activity.owner.email if activity.owner %\u003e added comment to \u003c%= activity.trackable.user.email %\u003e \n    \u003c% end %\u003e\n      \u003c/div\u003e\n    \u003c% end %\u003e\n\n\nadded comment to ...の部分を改良できないか？\nitemsテーブルとcommentsテーブルの間にリレーションを作り、trackされたcommentの要素の中にあるitem_idを使って、\nコメントしたitemのタイトルとそのリンク先を取得。ビューには次のように記載。\n\n  \u003c%= activity.owner.email if activity.owner %\u003e added comment to \u003c%= link_to activity.trackable.item.title, activity.trackable.item %\u003e \n\nやったぜ。\n\n= OmniAuthでGoogle \u0026 Facebook認証 + Devise\n長い時間を要した……\nここ[https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview]が一番参考になった。\n\nまずはgemをインストール\n\n  gem 'omniauth'\n  gem \"omniauth-facebook\"\n  gem \"omniauth-twitter\"\n  gem 'omniauth-google-oauth2'\n\nomniauth用のカラムをUserモデルに追加する。\n\n  rake db:reset\n\nしたあと、devise_create_users.rbというmigrationファイルを次のように書き換える。\n\n  class DeviseCreateUsers \u003c ActiveRecord::Migration\n    def change\n      create_table(:users) do |t|\n        ## Database authenticatable\n        t.string :email,              :null =\u003e false, :default =\u003e \"\"\n        t.string :encrypted_password, :null =\u003e false, :default =\u003e \"\"  \n\n        ## Recoverable\n        t.string   :reset_password_token\n        t.datetime :reset_password_sent_at  \n\n        ## Rememberable\n        t.datetime :remember_created_at  \n\n        ## Trackable\n        t.integer  :sign_in_count, :default =\u003e 0\n        t.datetime :current_sign_in_at\n        t.datetime :last_sign_in_at\n        t.string   :current_sign_in_ip\n        t.string   :last_sign_in_ip  \n\n        ##Omniauthable\n        t.integer :uid, :limit =\u003e 8 #bigintにする\n        t.string :name\n        t.string :provider\n        t.string :password  \n\n        ## Confirmable\n        # t.string   :confirmation_token\n        # t.datetime :confirmed_at\n        # t.datetime :confirmation_sent_at\n        # t.string   :unconfirmed_email # Only if using reconfirmable  \n\n        ## Lockable\n        # t.integer  :failed_attempts, :default =\u003e 0 # Only if lock strategy is :failed_attempts\n        # t.string   :unlock_token # Only if unlock strategy is :email or :both\n        # t.datetime :locked_at  \n\n        ## Token authenticatable\n        # t.string :authentication_token  \n  \n\n        t.timestamps\n      end  \n\n      add_index :users, :email,                :unique =\u003e true\n      add_index :users, :reset_password_token, :unique =\u003e true\n      add_index :users, :uid,  :unique =\u003e true\n      # add_index :users, :confirmation_token,   :unique =\u003e true\n      # add_index :users, :unlock_token,         :unique =\u003e true\n      # add_index :users, :authentication_token, :unique =\u003e true\n    end\n  end\n\nこれでもう一度\n\n  rake db:migrate\n\nする。次はこのmigrationに乗っ取ってmodels/user.rbを編集。\n\n  devise :database_authenticatable, :registerable,\n         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers =\u003e [:facebook, :google_oauth2]\n\n  # Setup accessible (or protected) attributes for your model\n  attr_accessible :email, :password, :password_confirmation, :remember_me\n  attr_accessible :name, :password, :uid, :provider\n  # attr_accessible :title, :body\n\n  validates :name, :presence =\u003e true, :uniqueness =\u003e true\n  validates :email, :presence =\u003e true, :uniqueness =\u003e true\n\nちょっとよけいなのも入ってるけど、これでオッケー。\n\n\n次はconfigの設定。config/initializers/devise.rbを書き換える。というか追記する。\n\n  OpenSSL::SSL.module_eval{ remove_const(:VERIFY_PEER) }\n  OpenSSL::SSL.const_set( :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE )\n  config.omniauth :facebook, \"APP_ID\", \"APP_SECRET\",\n      {:scope =\u003e 'email, offline_access'} \n  require \"omniauth-facebook\"\n  require \"omniauth-google-oauth2\"\n  config.omniauth :google_oauth2, \"4APP_ID\", \"APP_SECRET\", { access_type: \"offline\", approval_prompt: \"\" }\n\n上2行は必要。次にroutes.rbに下を追加。\n\n  devise_for :users, :controllers =\u003e { :omniauth_callbacks =\u003e \"users/omniauth_callbacks\" }\n \nビューに次のリンクを追加。\n\n  \u003c%= link_to \"Sign in with Facebook\", user_omniauth_authorize_path(:facebook) %\u003e\u003cbr /\u003e\n\n  \u003c%= link_to \"Sign in with Google\", user_omniauth_authorize_path(:google_oauth2) %\u003e\n\nその後、もう一度models/user.rbに次を追加。\n\n  def self.new_with_session(params, session)\n    super.tap do |user|\n      if data = session[\"devise.facebook_data\"] \u0026\u0026 session[\"devise.facebook_data\"][\"extra\"][\"raw_info\"]\n        user.email = data[\"email\"]\n        user.name = data[\"name\"]\n      end\n    end\n  end\n\n\n  def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)\n    data = access_token.extra.raw_info\n    if user = User.where(:email =\u003e data.email).first\n      user\n    else # Create a user with a stub password.\n      User.create!(:email =\u003e data.email, :name =\u003e data.name, :password =\u003e Devise.friendly_token[0,20], :provider =\u003e access_token.provider, :uid =\u003e access_token.uid)\n    end\n  end\n\n  def self.find_for_google_oauth2(access_token, signed_in_resource=nil)\n    data = access_token.info\n    if user = User.where(:email =\u003e data.email).first\n      user\n    else # Create a user with a stub password.\n      User.create!(:email =\u003e data.email, :name =\u003e data.name, :password =\u003e Devise.friendly_token[0,20], :provider =\u003e access_token.provider, :uid =\u003e access_token.uid)\n    end\n  end\n\nこれで最初登録したときにどんな情報が登録されるのかを設定できた。\n最後にapp/controllers/users/omniauth_callbacks_controller.rbというファイルを、ディレクトリごと作成。\n以下がその内容となる。\n  \n  class Users::OmniauthCallbacksController \u003c Devise::OmniauthCallbacksController\n    def facebook\n      # You need to implement the method below in your model\n      @user = User.find_for_facebook_oauth(request.env[\"omniauth.auth\"], current_user)  \n\n      if @user.persisted?\n        flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind =\u003e \"Facebook\"\n        sign_in_and_redirect @user, :event =\u003e :authentication\n      else\n        session[\"devise.facebook_data\"] = request.env[\"omniauth.auth\"]\n        redirect_to new_user_registration_url\n      end\n    end  \n\n    def google_oauth2\n        # You need to implement the method below in your model (e.g. app/models/user.rb)\n        @user = User.find_for_google_oauth2(request.env[\"omniauth.auth\"], current_user)  \n\n        if @user.persisted?\n          flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind =\u003e \"Google\"\n          sign_in_and_redirect @user, :event =\u003e :authentication\n        else\n          session[\"devise.google_data\"] = request.env[\"omniauth.auth\"]\n          redirect_to new_user_registration_url\n        end\n    end\n  end\n\nたぶんこれでオッケー。\nその他、deviseでの登録でもnameを登録できるように、views/registrations/new.html.erbに追記。\n\n  \u003cdiv\u003e\u003c%= f.label :name %\u003e\u003cbr /\u003e\n  \u003c%= f.text_field :name %\u003e\u003c/div\u003e\n\nほか、headerに表示されるemailを名前に変更。\nまあこれは簡単だろうから省略。\n長い道のりだった。\n\n= public_activityでフォローしているユーザーのアクティビティのみ表示\nまずviews/activities/index.html.erbを編集。\n\n  \u003ch1\u003eActivities#index\u003c/h1\u003e\n    \u003c% @activities.each do |activity| %\u003e\n        \u003c% if activity.trackable_type == \"Item\" %\u003e\n          \u003c% if activity.owner==current_user %\u003e\n           \u003cdiv class=\"activity\"\u003e\n            You made \u003c%= link_to activity.trackable.title, activity.trackable %\u003e\n           \u003c/div\u003e\n          \u003c% elsif @following.include?(activity.owner) %\u003e\n           \u003cdiv class=\"activity\"\u003e\n            \u003c%= activity.owner.name %\u003e made \u003c%= link_to activity.trackable.title, activity.trackable %\u003e\n           \u003c/div\u003e\n          \u003c% else %\u003e\n          \u003c% end %\u003e\n        \u003c% else %\u003e\n          \u003c% if activity.owner == current_user %\u003e\n          \u003cdiv class=\"activity\"\u003e\n            You added comment to \n            \u003c%= link_to activity.trackable.item.title, activity.trackable.item %\u003e \n            \u003c/div\u003e\n          \u003c% elsif @following.include?(activity.owner) %\u003e\n           \u003cdiv class=\"activity\"\u003e\n            \u003c%= activity.owner.name %\u003e\n             added comment to \n            \u003c%= link_to activity.trackable.item.title, activity.trackable.item %\u003e\u003cbr /\u003e\n           \u003c/div\u003e\n          \u003c% else %\u003e\n          \u003c% end %\u003e\n        \u003c% end %\u003e\n    \u003c% end %\u003e\n\nそのあと、activities_controller.rbに追記。\n\n  @following = current_user.following\n\nこれでよし。\n\n= DBをMySQLに変更する。\n\nとりあえず\n\n  mysql.server start\n\nしないと、mysql.sockがないとかで小一時間しかられた。\n次にmysql -u root -pでパスワードを入力してmysqlに入る。\nこれはPCと同じ。\nその後の内容はここ[http://www.oyabunn.com/wordpress/archives/60]を参照。\nめっちゃ見やすくなった。\n\n= Hirbでrails cを綺麗にする\n\nまずgemをインストールする。\n\n  gem 'hirb'\n  gem 'hirb-unicode'\n  gem 'pry-doc'\n\nそのあと、$home/.pryrc (~/.pryrcのこと)を新しく作成する。\nそして以下を記述。\n\n  begin\n    require 'hirb'\n  rescue LoadError\n    # Missing goodies, bummer\n  end  \n\n  if defined? Hirb\n    # Slightly dirty hack to fully support in-session Hirb.disable/enable toggling\n    Hirb::View.instance_eval do\n      def enable_output_method\n        @output_method = true\n        @old_print = Pry.config.print\n        Pry.config.print = proc do |output, value|\n          Hirb::View.view_or_page_output(value) || @old_print.call(output, value)\n        end\n      end  \n\n      def disable_output_method\n        Pry.config.print = @old_print\n        @output_method = nil\n      end\n    end  \n\n    Hirb.enable\n  end\n\nこれでオッケーヾ(๑╹◡╹)ﾉ\"\n\n= サムネイルを綺麗に表示 \u0026 ヘッダー少し大きめ\n\nそろそろhtmlやらなんやら綺麗にする。\nhome/_header.html.erbの項目を少し減らす。それでformやらなんやらも追加する。\n\n  \u003cli\u003e\u003cform class=\"form-search\" id=\"item\"\u003e\n    \u003cinput type=\"text\" class=\"input-medium search-query\" /\u003e \n    \u003cbutton type=\"submit\" class=\"btn\" id=\"item-search\"\u003eSearch\u003c/button\u003e\n    \u003c/form\u003e\n  \u003c/li\u003e\n\nそのあと、bootstrapを読み込んだあとにapplication.cssを読み込むようにする。\n\n  *= require bootstrap\n  *= require_self\n  *= require_tree .\n\nこのようにapplication.cssの記述の順番を変更。そうすると最後に読み込まれるapplicaiton.cssの方が優先される。\ncssはヘッダーの大きさやら背景やら、formの調整やらで次のようになった。\n\n  #header{\n    width:1024px;\n    margin-left: auto;\n    margin-right: auto;\n    padding:10px;\n  }  \n\n  .wrapper{\n    margin-top:100px;\n    width:1024px;\n    margin-right:auto;\n    margin-left:auto;\n  }  \n\n  .navbar-inner{\n    vertical-align: middle;\n    background : none;\n    background-color: white;\n  }  \n\n  form.form-search#item{\n    padding: 5px;\n    margin: 0px;\n  }  \n\n  button.btn#item-search {\n    margin-top: 0px;\n  }\n\n\n次にapp/uploaders/image_uploader.rbを次のように書き換える\n\n  version :thumb do\n     process :resize_to_fill =\u003e [280, 120]\n  end\n\n表示するviewを新たに作る。views/items/_thumb.html.erbを新たに作り、\nパーシャルを呼び出すようにitems/index.html.erbも書き換える。\nここには_thumbの記述だけのこす。\n\n  \u003cul class=\"thumbnails\"\u003e\n　  \u003c% @items.each do |item| %\u003e\n      \u003cli class=\"span4\"\u003e\n      \u003cdiv class=\"thumbnail\"\u003e\n        \u003c%= link_to image_tag(item.image_url(:thumb)), item %\u003e\n        \u003cdiv class=\"caption\"\u003e\n          \u003c%= item.user.name %\u003e\n          \u003ch3\u003e\u003c%= link_to item.title, item %\u003e\u003c/h3\u003e\n          \u003cp\u003e\u003c%= item.text %\u003e\u003c/p\u003e\n          \u003cp\u003e\n            \u003ca class=\"btn btn-primary\" href=\"#\"\u003eAction\u003c/a\u003e\n            \u003ca class=\"btn\" href=\"#\"\u003eAction\u003c/a\u003e\n          \u003c/p\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    \u003c% end %\u003e\n  \u003c/ul\u003e\n\n最後に元々テーブルで表示していたindex.html.erbの記述を消去。\nまだ改良の余地はある。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimakin%2Fapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fapper/lists"}