にルビーをf.selectする配列を渡す:は私がf.selectフィールドのコードを持つビュー/カード/ _formでの私のRailsアプリケーションでレール
:私に出力を与える<%= f.select :tag_speciality, options_for_select(@subdomain.tag_speciality), {}, {class: 'form-control'} %>
私は持っている私のマイグレーションファイルで
<select class="form-control" name="card[tag_speciality]" id="card_tag_speciality">
<option value="Professor de Yoga">Professor de Yoga</option>
<option value="Professora de Yoga">Professora de Yoga</option>
<option value="Estúdio de Yoga">Estúdio de Yoga</option>
</select>
:
add_column :cards, :tag_speciality, :string, array: true
私はフォームに移動し、任意のオプションを選択して、例えば、「教授・ド・ヨガ」、および保存、私を得ます結果:
[]
の代わり:
["Professor de Yoga"]
は、これは私のコントローラです:
def index
@cards = Card.all
end
def create
@card = @user.cards.new card_params
respond_to do |format|
if @card.save
format.html { redirect_to cards_from_subdomain_path(@subdomain.id), notice: 'Card was successfully created.' }
format.json { render :show, status: :created, location: @card }
else
format.html { render :new }
format.json { render json: @card.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @card.update(card_params)
format.html { redirect_to cards_from_subdomain_path(@subdomain.id), notice: 'Card was successfully updated.' }
format.json { render :show, status: :ok, location: @card }
else
format.html { render :edit }
format.json { render json: @card.errors, status: :unprocessable_entity }
end
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def card_params
params.require(:card).permit(
:name,
:phone,
:email,
:cover,
:is_published,
:subdomain_id,
:domain_id,
:profile_id,
:is_solidarity,
:tag_speciality,
:tag_location,
user_id: []
)
end
end
は、私が行方不明です何かありますか? ありがとう
コントローラコードを表示 –
あなたのコントローラに許可されたパラメータでtag_locationを入れましたか? –
はい、ちょうどコントローラを追加しました。tag_locationは既にコントローラの許可されたパラメータにあります。問題は配列に関するものであるように見えます:真のフィールド、単純な文字列フィールドの場合はnormalyを保存します。 .. –