Collection_select不保存数据

时间:2016-10-05 23:40:02

标签: mysql ruby-on-rails ruby

我在一个我想要执行的简单操作中遇到了一些问题。 为了解释上下文,我创建了新的Pin,我们可以在User表中标记绘画的艺术家(:pin_maker)。唯一的条件是用户是艺术家 目前,一切似乎都很好,但是当我运行创建功能时,它没有保存我的艺术家选择(或者:pin maker)

我的代码:

te Artist =

的范围
scope :artist, -> { where(artist: true) }

new pin(views)=

<div class="form-group">
<%= f.collection_select(:pin_maker, @users, :id, :pseudo, { }, {:multiple => true}) %>

controller pin =

    class PinsController < ApplicationController
  before_action :authenticate_user!
  before_action :find_pin, only: [:show, :edit, :update, :destroy, :upvote, :downvote]

  def index 
    @pins = Pin.all.order("created_at DESC")
  end 

  def show 
  end 



  def new
   @pin = Pin.new
   @users = User.all.artist
  end

  def create 
    @pin = current_user.pins.build(pin_params)
    if @pin.save 
      redirect_to @pin, notice: "successfully created!"
    else 
      render 'new'
    end
  end 

  def edit 

  end 

  def update 
    if @pin.update(pin_params)
      redirect_to @pin, notice: "successfully updated !"
    else 
      render 'edit'
    end
  end 

  def destroy
    @pin.destroy
    redirect_to root_path
  end 

  def upvote 
    @pin.upvote_from current_user
    redirect_to :back
  end 

  def downvote
    @pin.downvote_from current_user
    redirect_to :back
  end 

  private



  def pin_params
    params.require(:pin).permit(:title, :description, :image, :pin_maker)
  end 

  def find_pin
    @pin = Pin.find(params[:id])
  end 

end

所以,如果你对我应该改变什么有所了解,我就在这里!

0 个答案:

没有答案