0

我正在尝试使用简单的表单和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'
              } %>

我曾希望 '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
4

1 回答 1

0

不需要设置selected,simple_form 应该处理这个问题。尝试<%= debug par %>在编辑视图中输出以确保它具有您期望的值。

于 2015-06-12T10:24:41.753 回答