2011-09-22 38 views
0

我有一個select_tag挑選從這裏列表中的項目的問題是代碼:Rails的select_tag在表演和索引操作

<%= select_tag "Drinks", options_for_select([ "Water", "Soda", "Beer" ], "Water") %> 

submiting「水」爲爲例之後,它不會對指數出現了,在「飲料」部分展示意見。

我在做什麼錯?

控制器創建和更新方法

def create 
    @facture = Facture.new(params[:facture]) 

    respond_to do |format| 
     if @facture.save 
     format.html { redirect_to @facture, :notice => 'Facture was successfully created.' } 
     format.json { render :json => @facture, :status => :created, :location => @facture } 
     else 
     format.html { render :action => "new" } 
     format.json { render :json => @facture.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 


def update 
    @facture = Facture.find(params[:id]) 

    respond_to do |format| 
     if @facture.update_attributes(params[:facture]) 
     format.html { redirect_to @facture, :notice => 'Facture was successfully updated.' } 
     format.json { head :ok } 
     else 
     format.html { render :action => "edit" } 
     format.json { render :json => @facture.errors, :status => :unprocessable_entity } 
     end 
    end 
    end   
+0

你正在顯示的代碼是索引和顯示嗎? – Salil

+0

實際的代碼是關閉的「_form.html.erb」 – blawzoo

+1

請發佈您的控制器的創建/更新代碼 – arnep

回答

1

應使用此:[:骨折]

select_tag "facture[drinks]", options_for_select([ "Water", "Soda", "Beer" ], "Water") 

的方法是使用在PARAMS發送的值的創建和使用 「骨折[飲料]」將其作爲params [:facture] [:飲料]包含在內。

+0

Hoooooooo Yeahhhhh !!! Miligraf你殺了它,非常感謝... – blawzoo

+0

De nada amigo,它發生在我身上很多...記得總是記錄你的問題解決方案。 – miligraf

0

下面是如何進行(感謝miligraf):

1-讓控制器/ factures代碼完整

2-變化的代碼在視圖/ factures/_form.html.erb:

<%= select_tag "facture", options_for_select([ "Water", "Soda", "Beer" ], "Water") %> 

以前

<%= select_tag "facture[drinks]", options_for_select([ "Water", "Soda", "Beer" ], "Water") %>