我有一个表单来创建一个“Adherent”(就像一个非营利组织的成员),有两个提交按钮。第一个只创建“粘附者”,第二个“创建粘附者并显示账单”(因为粘附者必须付费)。
我正在使用 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'
附着者控制器
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 制作得很好,但我无法展示它。我认为问题在于它@facture_adhesion
是空的。但是我怎样才能从 FactureAdhesion/show 得到它?:locals =>
好像不行。。。
有人有想法吗?谢谢