ガイドラインを削除するのではなく、非表示としてマークを付けたいのです(したがって、ガイドラインはまだデータベースにありますが、ユーザーには表示されません)。これにはいくつかの大きな問題があります
- ビューからガイドラインを削除できないようです
- 管理者側を表示しようとすると、ガイドラインでエラーが発生します
ActionView :: Template :: Error(#の未定義のメソッド `comment_ids_contains'):
2番は無関係だと思いますが、以下の変更を行う前は問題は発生しませんでした。私のguidelines.rbモデルに追加しました
default_scope where(:visible => true)
attr_accessible :visible
guideline_controller.rbで、destroyおよびcreateアクションをに変更しました
def destroy
@guideline = Guideline.find(params[:id])
@guideline.visible=false
#@guideline.destroy
respond_to do |format|
format.html { redirect_to guidelines_url }
format.json { head :no_content }
end
end
def create
@guideline = current_user.guidelines.new(params[:guideline])
@guideline.visible=true
respond_to do |format|
if @guideline.save
format.html { redirect_to @guideline, notice: 'Guideline was successfully created.' }
format.json { render json: @guideline, status: :created, location: @guideline }
else
@specialties = Guideline.order(:specialty).uniq.pluck(:specialty)
format.html { render action: "new" }
format.json { render json: @guideline.errors, status: :unprocessable_entity }
end
end
end
admin/guidelines.rbに追加しました
column :visible
そして私はdb移行を追加しました
class AddVisibleColumnToGuidelines < ActiveRecord::Migration
def change
add_column :guidelines, :visible, :boolean
end
end