我正在尝试使用简单的表单和money-rails在rails 4中创建一个应用程序。
我的模型中有属于货币化的属性。
当我创建新表单并保存属性时,我希望在我回来编辑表单时显示这些已保存的输入。目前,我正在尝试:
<%= par.input :participation_cost,
label: false,
placeholder: 'Whole numbers only',
selected: :participation_cost,
:input_html => {
:style => 'width: 250px; margin-top: 20px',
class: 'response-project'
} %>
我曾希望选择:: participation_cost,显示所选输入。它没有。单击编辑以编辑表单时,将返回列表顶部。
我的参与者控制者有:
class ParticipantsController < ApplicationController
before_action :set_participant, only: [:show, :edit, :update, :destroy]
# GET /participants
# GET /participants.json
def index
@participants = Participant.all
end
# GET /participants/1
# GET /participants/1.json
def show
end
# GET /participants/new
def new
@participant = Participant.new
end
# GET /participants/1/edit
def edit
end
# POST /participants
# POST /participants.json
def create
@participant = Participant.new(participant_params)
respond_to do |format|
if @participant.save
format.html { redirect_to @participant, notice: 'Participant was successfully created.' }
format.json { render action: 'show', status: :created, location: @participant }
else
format.html { render action: 'new' }
format.json { render json: @participant.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /participants/1
# PATCH/PUT /participants/1.json
def update
respond_to do |format|
if @participant.update(participant_params)
format.html { redirect_to @participant, notice: 'Participant was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @participant.errors, status: :unprocessable_entity }
end
end
end
# DELETE /participants/1
# DELETE /participants/1.json
def destroy
@participant.destroy
respond_to do |format|
format.html { redirect_to participants_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_participant
@participant = Participant.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def participant_params
params[:participant].permit(:title, :description, :location, :costs, :participation_cost,
:eligibility, :eligibility_criteria, :currency, :participation_cost_pennies, :participation_cost_currency,
:location_specific )
end
end
答案 0 :(得分:0)
没有必要设置selected
,simple_form应该处理这个问题。尝试在编辑视图中输出<%= debug par %>
,以确保它具有您期望的值。