mercredi 28 octobre 2015

How to load partial with using ajax

Indeed, in spite of setting ajax loading as 'remote=>true', it loads the url

'/noajax_en/v/yt/' + @movie.uid + '/refresh_part_after_comment'

Why it won't load ajax? it should load the url this below

'/en/v/yt/' + @movie.uid + '/refresh_part_after_comment'

Here's my code

view

<%= form_for(@comment, :url => {:controller => "comments", :action => "create" }, :remote => true) do |f| %>
    <%= f.text_field :body, id:"body_input" %>
    <%= f.hidden_field :elapsed_time, id: "elapsed_time" %>
    <%= f.hidden_field :video_id, value: params[:uid] %>
    <%= button_tag( :class => "btn btn-primary") do %>
        Post
    <% end %>                   
<% end %>

comments_controller.rb

def create
    .
    .
    .
    flash[:notice] = "posted"       

    if request.xhr?  # ajax request
        respond_to do |format|
            render '/en/v/yt/' + @movie.uid + '/refresh_part_after_comment'
        end
    else
            redirect_to '/noajax_en/v/yt/' + @movie.uid + '/refresh_part_after_comment'
    end
end

Aucun commentaire:

Enregistrer un commentaire