Closed ryohakjae114 closed 5 months ago
gem solargraphをグローバルにインストール
erbをhamlに変換
miniblog.testというサブドメインからもlocalhostにアクセスできるように config.hosts << 'miniblog.test'
config.hosts << 'miniblog.test'
routesにpostsコントローラのnewアクションを追加する
postsコントローラのnewアクションを作成してページを作成する
@post
rails generate simple_form:install --bootstrap
= simple_form_for @post do |f| = f.input :body = f.submit
postsコントローラのcreateアクションを作成する
def create @post = Post.new(post_params) if @post.save redirect_to new_post_path, notice: '投稿しました' else render :new, status: :unprocessable_entity end end
private
def post_params params.require(:post).permit(:body) end
* simple_formで作成するボタンのデフォルトの色を青色にする ` config.button_class = 'btn btn-primary' ` * 登録したらメッセージを表示する * flash_messageパーシャルをlayoutsに作成する * application.html.hamlにflash_message.html.hamlをrenderする
- flash.each do |_message_type, message| .alert.alert-success.fade.show.alert-dismissible = message %button.btn-close{'aria-label' => 'Close', 'data-bs-dismiss' => 'alert', type: 'button'} ```
gem solargraphをグローバルにインストール
erbをhamlに変換
miniblog.testというサブドメインからもlocalhostにアクセスできるように
config.hosts << 'miniblog.test'
routesにpostsコントローラのnewアクションを追加する
postsコントローラのnewアクションを作成してページを作成する
@post
のインスタンスを作成するrails generate simple_form:install --bootstrap
postsコントローラのcreateアクションを作成する
private
def post_params params.require(:post).permit(:body) end
@post
を渡す)