1

这是我的控制器:

class ReportNeedsController < ApplicationController
def index
@report_needs = nil
end
  def new
     @report_need = ReportNeed.new
  end    
  def create
     @report_need = ReportNeed.new(params[:report_need])
     @report_need.save
     redirect_to @report_need
  end
end

这是我的 new.haml 文件:

为什么要举报?

%form
    %input{:name => "option", :type => "radio", :value => "spam"}
    spam                   
    %br/    

enter code here


    %input{:name => "option", :type => "radio", :value => "product_corrupted"}      
    product_corrupted                   
    %br/                      
    %input{:name => "option", :type => "radio", :value => "product_spoiled"}       
    product_spoiled
4

1 回答 1

0

在视图中进行更改,例如:

  %input{:type => "radio", :name => "report_need[product_type]", :id => "report_need[product_type]-1", :value => "salesforce", :checked => true}
  %br/
  %input{:type => "radio", :name => "report_need[product_type]", :id => "report_need[product_type]-2", :value => "salesforce", }

在控制器中,如果product_type是表report_needs的字段,则无需更改您的操作。否则它的变化和存储它像:

  def create
     report_need = ReportNeed.new(params[:report_need])
     report_need.radio_field_name = params[:report_need][product_type]
     report_need.save
     redirect_to report_need
  end
于 2012-04-19T12:05:19.627 回答