0
我有一個表單用於創建「Adherent」(如非營利組織的成員),並帶有兩個提交按鈕。 第一個只創建「貼心」,第二個「創建貼心和展示賬單」(因爲貼心必須付錢)。Rails3 - 在創建後編輯並顯示帳單
我正在使用Ajax。
所以我有:AdherentsController和FactureAdhesionController。 我的問題是,創建貼圖後無法顯示帳單。
登錄:
ActionView::Template::Error (undefined method `nom_adherent' for nil:NilClass):
2:
3:
4:
5: <%= @facture_adhesion.nom_adherent %>
app/views/facture_adhesions/_show.html.erb:5:in `_app_views_facture_adhesions__show_html_erb__741033609_23539632'
app/controllers/adherents_controller.rb:141:in `block (2 levels) in create'
app/controllers/adherents_controller.rb:135:in `create'
AdherentsController
def create
@adherent = Adherent.new(params[:adherent])
# if params[:commit] == "Valider" do things
elsif params[:commit] == 'Valider et éditer une facture' #si on a cliqué sur "valider et voir la facture"
if @adherent.save
@facture = FactureAdhesion.new(
:date_adhesion => @adherent.date_adhesion,
:dimension_date_id => num_aujourdhui,
:nom_adherent => @adherent.nom,
:prenom_adherent => @adherent.prenom,
:adresse1 => @adherent.adresse1,
:adresse2 => @adherent.adresse2,
:code_postal => @adherent.code_postal,
:ville => @adherent.ville,
:telephone => @adherent.numero_telephone,
:adresse_mail => @adherent.adresse_mail,
:montant => @adherent.type_tarif.montant,
:libelle => "Adhesion"
)
respond_to do |format|
if @facture.save
format.html { redirect_to @adherent, notice: 'Adherent was successfully created.' }
format.json { render json: @adherent, status: :created, location: @adherent }
format.js do
render :inline => affichage_sur_panneau_principal + '$("#panneau_principal").html("<%= j (render(:partial => "facture_adhesions/show", :locals => {:facture_adhesion => @facture})) %>");' + gerer_loading
end
else
format.html { render action: "new" }
format.json { render json: @adherent.errors, status: :unprocessable_entity }
format.js {render :inline => '$("#panneau_principal").html("<%= j (render(:partial => "adherents/new")) %>")'}
end
end
end
end
FactureAdhesions /顯示
<%= @facture_adhesion.nom_adherent %>
的骨折很好地建立,但我不能表現出來。我認爲問題在於@facture_adhesion
是空的。但是我怎樣才能從FactureAdhesion/show中獲得它? :locals =>
似乎不工作...
有人有想法嗎? 謝謝
謝謝Grotori。我認爲通過變量:當地人做了這項工作......但現在它的工作!再次感謝 – 2013-04-30 10:56:24