0

こんにちは私はshow.html.erbに推定予算を表示しています

私はこのコードを使用しています:

<%= current_user.agency.project_procurement_management_plans.map{|p| p.total_estimated_budget.to_s} %>

しかし、その後、出力は次のようになります。

["117000.5"]

内部の出力を切り離すにはどうすればよいですか?[""]

配列(?)のせいだと思いますが、どうすればそれを防ぐことができますか?

同様に、コントローラーでこのコードを実行している場合:

def create
    @project_procurement_management_plan = ProjectProcurementManagementPlan.new(params[:project_procurement_management_plan])

    respond_to do |format|
      if @project_procurement_management_plan.save
        format.html { redirect_to @project_procurement_management_plan, notice:"#{@project_procurement_management_plan.code} was successfully created." }
        format.json { render json: @project_procurement_management_plan, status: :created, location: @project_procurement_management_plan }
      else
        #change me soon
        format.html { redirect_to  new_project_procurement_management_plan_path, alert:"#{@project_procurement_management_plan.errors.full_messages}"}
        format.json { render json: @project_procurement_management_plan.errors, status: :unprocessable_entity }
      end
    end
  end

エラーメッセージは、[""]

例えば

["Name can't be blank","The password is incorrect"]

等々。

任意の回避策をいただければ幸いです。ありがとう。

4

1 に答える 1

2

はい、mapすべての要素を含む配列を返しますか。1つしかない場合は、使用しないでくださいmap

<%= current_user.agency.project_procurement_management_plans.first.total_estimated_budget.to_s %>

編集

エラーについては

@project_procurement_management_plan.errors.full_messages.to_sentence

これにより、エラーがカンマ

于 2013-03-12T00:55:07.357 に答える