2014-12-18 4 views
0

Я хотел бы предупредить подтверждение успеха при создании получателей, но я получаю ошибку недостающий шаблон:рендеринга через AJAX в рельсах

ActionView::MissingTemplate - Missing partial recipients/_recipient 
    with {:locale=>[:fr], :formats=>[:js, :html], 
    :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. 

RecipientController.rb

respond_to :html 

    def index 
    @recipients = Recipient.all 
    respond_with(@recipients) 
    end 

    def create 
    @recipient = Recipient.new(recipient_params) 

    if @recipient.save 
     #RecipientMailer.confirmer_mon_inscription(@inscription).deliver 
     #@recipient.destroy 
     respond_to do |format| 
     format.html { redirect_to @article, 
         :notice => 'Thanks for your comment' } 
     format.js { render 'success_create.js.erb'} 
     end 
    else 
     respond_to do |format| 
     format.html { redirect_to @article, 
         :alert => 'Unable to add comment' } 
     format.js { render 'fail_create.js.erb' } 
     end 
    end 
    end 

success_create. js.erb

alert("<%= @recipient.email %>"); 

fail_create.js.erb

alert("<%= @recipient.errors.full_messages.to_sentence %>"); 

есть что-то, что я не понимаю, почему я должен создать частичную _recipient для создания действия, когда я уже указать, какой файл для отображения

это моя форма

<h1>S inscrire à la newsletter</h1> 

<div class="newsletter"> 
    <div class="newsletter-contenu"> 
    <%= form_for(@recipient, :remote => true, :html => {:class => "form-group"}) do |f| %> 
     <div class="field form-group"> 
     <%= f.label :email %><br /> 
     <%= f.text_field :email %> 
     </div> 
     <div class="actions form-group"> 
     <%= f.submit "S'inscrire à la newsletter", :class => "btn btn-info" %> 
     </div> 
    <% end %> 
    </div> 
</div> 

ответ

1

Вам не хватает опции :file, как описано в документах here. Это должно работать

format.js { render file: 'fail_create.js.erb' } 
Смежные вопросы