質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

913閲覧

acts_as_taggable ダグ機能実装

nm3000623

総合スコア11

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/07/11 06:39

challenge記事にタグを付けたいのですが、このようなエラーが出てしまいます。
どうしてでしょうか。
よろしくお願いします。

class Challenge < ApplicationRecord belongs_to :user acts_as_taggable validates :titile, presence: true, length: { maximum: 255 } validates :description, presence: true, length: { maximum: 255 } end
class ChallengesController < ApplicationController before_action :require_user_logged_in before_action :correct_user, only: [:destroy] def index if logged_in? @user = current_user @challenge = current_user.challenges.build # form_for 用 @challenges = current_user.challenges.order('created_at DESC').page(params[:page]) end end def new @challenge = Challenge.new end def create @challenge = current_user.challenges.build(challenge_params) if @challenge.save flash[:success] = 'メッセージを投稿しました。' redirect_to root_url else @challenges = current_user.challenges.order('created_at DESC').page(params[:page]) flash.now[:danger] = 'メッセージの投稿に失敗しました。' render 'toppages/index' end end def destroy @challenge.destroy flash[:success] = 'メッセージを削除しました。' redirect_back(fallback_location: root_path) end private def challenge_params params.require(:challenge).permit(:titile, :description, :tag_list) end def correct_user @challenge = current_user.challenges.find_by(id: params[:id]) unless @challenge redirect_to root_url end end end
class UsersController < ApplicationController before_action :require_user_logged_in, only: [:index, :show] def index @users = User.all.page(params[:page]) end def show if logged_in? @user = current_user @challenge = current_user.challenges.build # form_for 用 @challenges = current_user.challenges.order('created_at DESC').page(params[:page]) end @user = User.find(params[:id]) @challenges = @user.challenges.order('created_at DESC').page(params[:page]) counts(@user) end def new @user = User.new end def create @user = User.new(user_params) if @user.save flash[:success] = 'ユーザーを登録しました' redirect_to @user else flash.now[:danger] = '登録に失敗しました' render :new end end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end end
<div class="field form-group form-group-lg"> <%= f.label :tag_list, class: "sr-only control-label" %> <%= text_field_tag 'draft[tag_list]', draft.tag_list.join(","), class: "form-control" %> </div> <%= form_for(@challenge) do |f| %> <div class="form-group"> <%= f.text_area :titile, class: 'form-control', rows: 1 %> <%= f.text_area :description, class: 'form-control', rows: 5 %> </div> <%= f.submit 'Post', class: 'btn btn-primary btn-block' %> <% end %>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問