我正在尝试用rails 4做一个应用程序,使用简单的表单和money-rails。
当我创建一个新表单并保存属性时,我希望这些保存的输入在我回来编辑表单时显示出来。目前,我正在尝试:
<%= par.input :participation_cost,
label: false,
placeholder: 'Whole numbers only',
selected: :participation_cost,
:input_html => {
:style => 'width: 250px; margin-top: 20px',
class: 'response-project'
} %>我曾希望“selected::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发布于 2015-06-12 18:24:42
应该没有必要设置selected,simple_form应该可以处理这个问题。尝试在编辑视图中输出<%= debug par %>,以确保它具有您所期望的值。
https://stackoverflow.com/questions/30800090
复制相似问题