1
タグとユーザーの多対多の関連付けがあります。私が参加し、テーブルが私の更新されないタグを作成するとき、私はコントローラとの何かがあると思う ...Ruby on Rails HABTMアソシエーションは結合テーブルを更新しません
タグモデル
class Tag < ActiveRecord::Base
validates :tag, :presence => true
has_and_belongs_to_many :user, :join_table => "tags_users"
end
ユーザモデル
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation,:remember_me
has_and_belongs_to_many :tag, :join_table => "tags_users"
end
tags_controller
class TagsController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
def create
@tag = Tag.new(params[:tag])
respond_to do |format|
if @tag.save
format.html { redirect_to tags_path, notice: 'Tag was successfully created.' }
format.json { render json: @tag, status: :created, location: @tag }
else
format.html { render action: "new" }
format.json { render json: @tag.errors, status: :unprocessable_entity }
end
end
end
end