keit1722
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Keiポートフォリオ ### サイトのURL https://listing-app.net/ ### ダミーユーザー |権限|email|password|ログインページ| |:-|:-|:-|:-| |一般|guest@example.com|password|https://listing-app.net/login| |ビジネス|business@example.com|password|https://listing-app.net/business/login| |アドミン|admin@example.com|password|https://listing-app.net/pvsuwimvsuoitmucvyku/login| ### GitHubリポジトリ https://github.com/keit1722/listing_app ### DB設計・エンドポイント https://github.com/keit1722/listing_app_blueprint ### アプリの説明 私の地元の情報のみを扱ったトリップアドバイザーのようなアプリです(口コミ機能無し)。地域貢献・地元の活性化を目的としています。 私の地元は観光地ですが、地域の情報をまとめたサービスが少なかったので作成しました。 地元のお店などに対して営業活動おこない、情報を載せて行く予定です。 「listing app」というアプリ名はとりあえず付けたものです。サービス開始時期が決まっていないため、開始時に正式なものに変更します。 ### 主な機能 - CRUD機能 - User - Organization - Restaurant - Hotel - Activity - HotSpring - SkiArea - PhotoSpot - Shop - Post - Announcement - 会社や個人事業などの「組織」を登録するの管理者による承認機能 - 既存の組織からユーザーに対しての招待機能 - お気に入り登録機能 - メール通知設定機能 - Google OAuthによるユーザ登録・ログイン - ユーザーアカウントのアクティベーション機能(Sorcery) - ユーザーアカウントのパスワードリセット機能(Sorcery) ### 技術的に苦労したところ - フォームオブジェクトを用いた複数モデル同時登録・編集 - 招待機能 - 承認申請機能 - 共通で使うモデルが多かったのでポリモーフィック関連付け多用した - ビューの数が多かったためパーシャルを多用した # レビュー ## だいそん - READMEに環境構築手順が書いてあるのがGood - RSpec, rubocop, CIが入ってるのがGood - ユーザー承認 -> ユーザー認証 が正しい - `database.for.heroku.ridgepole.yml`ってなんのためにあるんだっけか - 本番のsidekiqはベーシック認証をかけた方が良い - ここgetで問題ない?DBの更新系はPOSTかPATCHの方がベター ```rb= resources :users, only: [] do member { get :activate } end ``` - 単一resourceの場合は単数系の方がしっくりくる ```rb= resource :bookmarks, only: %i[create destroy], module: :restaurants ``` - コントローラのディレクトリもしっかり切られていてGood - 単なるidではなくslugを使ってるのもユーザーフレンドリーでGood ```rb= resources :hotels, param: :slug, only: %i[index show] do ``` - 飲食店ごとの投稿ページのURLがちょっとネストが深い気もする。 ``` https://listing-app.net/restaurants/ward/posts/5 ``` シンプルにこれでも良い気がしてきた。 ``` https://listing-app.net/posts/5 ``` - リソースごとに営業時間を設定するの大変そうですね。どのように管理してるのか教えて欲しい。 - 飲食店、宿泊施設、アクティビティなど、それぞれ持ってるカラムが同じ(またはほぼ同じ)なのであればSTI(単一テーブル継承)を使うのもありだったかもしれない。そうすればテーブル自体は一つで済む。そうするとポリモーフィック ```rb= class Listing < ApplicationRecord # record_type 'Hotel' | 'Activity' end class Hotel < Listing has_many :categories end class Activity < Listing end ``` - しっかり意味のあるまとまりとしてロジックをmoduleに切り出していてGood ```rb= class Hotel < ApplicationRecord include ActiveModel::Validations belongs_to :organization include Districtable include Bookmarkable include Postable include ReservationLinkable include OpeningHourable include PageShowable ``` - ビジネスユーザーと一般ユーザーは完全に分けちゃった方が色々と実装はしやすいかもしれない - カテゴリ設定のinputは何かライブラリを使ってるんですか? ```rb= Bookmark.create(bookmarkable: bookmarkable, user_id: current_user.id) ``` ```rb= # app/controllers/concerns/bookmarkable.rb module Bookmarkable extend ActiveSupport::Concern # おまじない included do before_action :set_bookmarkable, only: [~~~] end private def set_bookmarkable raise NotImplementError, ~~~ end end # app/controllers/activities/bookmarks_controller.rb class Activities::BookmarksController < ApplicationController include Bookmarkable private def set_bookmarkable ~~~ = Activity.~~~~~ end end class Hotels::BookmarksController < ApplicationController include Bookmarkable private def set_bookmarkable ~~~ = Hotel.~~~~~ end end ``` ## みけた すごい。弊社に来てくれ。 schema.rbが400行は仕事やん。 ただ、これだけじゃレビューとはいえないので、とりあえずcustomer.rbだけ見てみました。 - association, callback, validationあたりの設定が整理されていない部分があるので、整えてあげると見やすくなりそうです - sendメソッドを駆使していてすげえとなりました。ただ、セキュリティ的に脆弱性を生みやすいので、注意を特に払うようにしてください! - destroyの引数は不要なのでは?(ちなみに、Article.destroy(1)といった書き方はできるようです: https://pikawaka.com/rails/destroy#destroyメソッドの引数 ```rb= def unbookmark(bookmarkable) send(bookmark_object(bookmarkable)).destroy(bookmarkable) end ``` ```rb= def resign(organization) organizations.destroy(organization) end ``` あと、BookmarksControllerとActivities::BookmarksControllerの関係なんかを見て、 継承を使って面白い実装をしているなと思いました。あくまで個人的な意見ですけど、継承していることが分かりづらいので、 こういう書き方をしてみるのも良いのかもしれないなと思いました。 変更前 ```rb= class BookmarksController < ApplicationController before_action :require_login def create current_user.bookmark(@bookmarkable) render 'listings/bookmarks/create' end def destroy current_user.unbookmark(@bookmarkable) render 'listings/bookmarks/destroy' end end class Activities::BookmarksController < BookmarksController before_action :set_bookmarkable, only: [:create, :destroy] private def set_bookmarkable @bookmarkable = Activity.find_by(slug: params[:activity_slug]) end end ``` 変更後 ```rb= class BookmarksController < ApplicationController before_action :require_login before_action :set_bookmarkable, only: [:create, :destroy] def create current_user.bookmark(@bookmarkable) render 'listings/bookmarks/create' end def destroy current_user.unbookmark(@bookmarkable) render 'listings/bookmarks/destroy' end private def set_bookmarkable # 必ず継承先でオーバーライドすること raise NotImplementedError '@bookmarkableがsetされていません' end end class Activities::BookmarksController < BookmarksController private def set_bookmarkable @bookmarkable = Activity.find_by(slug: params[:activity_slug]) end end ``` インスピレーションは、ここで受けています。 https://qiita.com/joker1007/items/9da1e279424554df7bb8 ただ、継承っていうのは、共通化させる作業なので、継承先の一部においてのみで特殊な分岐をしたいって場面が増えてくると、 ロジックがとにかく汚くなって破滅の道へと突き進むイメージです。 (奇特な事例しか思いつかないですが、例えば、activityのときだけrenderするtemplateを変えたい場合など。) https://twitter.com/minodriven/status/1353251239237095430 このケースは、もしかしたらBookmarksControllerを削除して、Activities::BookmarksControllerでモジュールをincludeする形がよいかもしれないです。 私だったら、モジュールをincludeすることもせず、DRYには反しますが、同じコードをペタペタ貼るほうを選択するかなと思いました。 私が間違っていることを言っている可能性は十分にあるので、だいそんさんに相談してみてください。 ## maki(wip) PF作成、お疲れ様です! 自分も全然レビューできる立場の人間ではないので、参考程度にしてもえると! - 全体的な感想 - すごい!サイト全体が見やすくいい感じで、素直にすごいなと思いました! - TBL設計 - 営業時間のstart_time_hourやstart_time_minute などがstringで定義しているのって何か、こだわりがあったりしますか? 個人的にはtimeにした方が良いと思いました。理由は、バリデーションをかけるのも辛いし、今後、「現時刻で営業中の場所を絞り込む」みたいな機能を作るのも結構辛そうな気がします。 ```start_time_hour, [*0..23]```みたいに書くのも、dateにしてrubyでロジックを考えた方が良さそうな記載しました。 - 施設情報は持ってるカラムは同じなのですかね?まとめられそうな。。。 - その他・質問等 - 1つの温泉宿で宿泊してない人もレストランを利用できるみたいな、複数カテゴリにまたぐ施設があった場合データはどう持ちますかね? - schema.rbが400行はすごいですが、table毎にファイル分割されてた方が好みだったりします。個人で作る場合は関係ないかもですが、複数人開発だとコンフリクトが起こりそうです。 (だいそん) Time.zone.parse("2022-01-01"), Time.zone.local(2022, 1, 1) rails console -> eigyojikan.update(start_time_hour: '12:00') eigyojikan.start_time_hour # 2001 1 1 12:00 gem month https://github.com/readysteady/month ## Shun - 感想 - 最初ページを開いた時、すでに運営されてるサイトかなと思ったくらいの完成度です。 - このポートフォリオだと企業の引く手あまたな気がします! - 気になった点 - メールアドレスでユーザー登録したのですが、認証のメールが送られてこず...迷惑メールBOXも見たのですが見当たらずでした。再度試して、「メールアドレスはすでに存在します」のフラッシュが表示されているので、メール送信で不具合が発生しているのかなと...(自分の確認ミスでしたら申し訳ないです) - ユーザー登録や編集ページにおいて、フォーム部分が冗長な気がするので部分テンプレート(`_form.html.erb`)で書き出したほうがいいかなと思いました。 - `app/views/shared/_header_navigation.html.erb`や`app/views/shared/users/_show.html.erb`のアバター画像表示のロジックですが、 user登録の際にデフォルト画像を登録する方法もあります。そうすると、以下のロジックだけで済みます。 ```ruby <div class="avatar-preview margin-bottom-30"> <% if user.avatar.attached? %> <%= image_tag user.avatar %> <% else %> <%= image_tag 'blank-profile-picture.png' %> <% end %> </div> ↓修正後 <div class="avatar-preview margin-bottom-30"> <%= image_tag user.avatar %> </div> ``` ```ruby # app/models/user.rb class User < ApplicationRecord before_create :default_avatar def default_avatar return avatar if avatar.attached? avatar.attach(io: File.open(Rails.root.join('app/assets/images/blank-profile-picture.png')), filename: 'blank-profile-picture.png') end end ``` 参考:[Active Storageでデフォルト画像を設定する - qiita](https://qiita.com/mashihiko_397/items/569384b8f8f333b3168e) - 細かいですが、レイアウト崩れしておりました。 [![Image from Gyazo](https://i.gyazo.com/c4f558bf8158d10c95d57e0736ffc693.png)](https://gyazo.com/c4f558bf8158d10c95d57e0736ffc693) [![Image from Gyazo](https://i.gyazo.com/e89d4f130bf1957c81d1532ca070644f.png)](https://gyazo.com/e89d4f130bf1957c81d1532ca070644f) - 良かった点 - `to_params`いいですね。`/users/1`よりずっと親切設計です。 - インデントや改行がきちんとされているのでコードが見やすいです。 ## Todaka ### 感想 - ポートフォリオ作成、お疲れ様でした!この規模で作り切るのは本当に凄いと思います。 - 他の方も言われてますけど、凄すぎて個人開発感はゼロですね笑 - ダミーデータも気合が入っているので、実際に使われているような 印象を受けました! ### その他コメント - お店やスキー場などのリスト表示について、リストの件数をコントローラでカウントしてビューに渡す必要があるか気になりました。ビュー側で`listings.count`と書くだけでは表示されないですかね? - 各コントローラにある`render layout: 'listings_index'`や`render layout: 'listings_single'`の挙動を教えていただきたいです。 - プロフィール画面について、見出しの説明がちょっと冗長な気がしました(特にスマホ表示)。なくても意味がわかる項目は見出しを省いても良いかもしれません。 - [![Image from Gyazo](https://i.gyazo.com/bb8230d4ca94239a880b8e054e456783.png)](https://gyazo.com/bb8230d4ca94239a880b8e054e456783) - プロフィール画面について、特定の状況(15.6型ディスプレイを縦置き)で見ると、メニューバーの表示が少し変な感じです。ただ、横置きのディスプレイでデベロッパーツールを使って確認しても再現できなかったので、スルーしてもらって大丈夫です。 - [![Image from Gyazo](https://i.gyazo.com/ffcef0bf0484c4831e1bef5c3a15ea47.png)](https://gyazo.com/ffcef0bf0484c4831e1bef5c3a15ea47) - Shunさんがおっしゃってたメール配信について、todakaが試したところ問題なく受信できました(一応ご報告)。 ```rb= create_table "page_shows", force: :cascade do |t| t.bigint "page_showable_id" t.string "page_showable_type" t.json "setting" t.datetime "updated_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false t.index ["page_showable_type", "page_showable_id"], name: "index_page_shows_on_page_showable_type_and_page_showable_id" end setting = { "reservation_link": true, "opening_hours": false, } JSON型。半構造化データ。 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully