samedi 19 septembre 2015

Error in Rails Ajax

I used to follow coderwall tutorial in ajax but I got ActionController::UnknownFormat when I open to new tab the following link <%= link_to 'Link Name', fetch_items_path(:cat_id => cat.id), :remote => true %>. What's wrong with this? Thanks!

In additional, when I click the link it doesn't respond to anything.

Here is the

Controller:

def from_category
  @selected = Item.find(params[:cat_id])
  respond_to do |format|
    format.js
  end
end

Views index.html.erb

1), :remote => true %>

_items.list.html.erb

<% items.each do |item| %>
  <div class="item_box">
    ...
  </div>
<% end %>

item_grid.html.erb

<div>
  <div id="items_grid" >
    <%= render partial: 'items_list', locals: {items: items}  %>
  </div>
</div>

from_category.js.erb

$("#items_grid").html("<%= escape_javascript(render partial: 'items_list', locals: { items: @selected } ) %>");

Aucun commentaire:

Enregistrer un commentaire