首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails -简单表单- Money-Rails gem -编辑时显示选择

Rails -简单表单- Money-Rails gem -编辑时显示选择
EN

Stack Overflow用户
提问于 2015-06-12 17:48:00
回答 1查看 318关注 0票数 0

我正在尝试用rails 4做一个应用程序,使用简单的表单和money-rails。

当我创建一个新表单并保存属性时,我希望这些保存的输入在我回来编辑表单时显示出来。目前,我正在尝试:

代码语言:javascript
复制
<%= 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”会显示所选的输入内容,但事实并非如此。当您单击“编辑”来编辑表单时,将返回到列表的顶部。

我的参与者控制器有:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2015-06-12 18:24:42

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30800090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档