我有一些聯繫,我想發送POST請求,但他們發送得到軌的link_to將獲得的,而不是後
<p class="tags">
<% tags.keys.each do |key| %>
<% if tags[key] == 1 %>
<%= link_to by_tag_media_path(:tag => key), :remote => true, :method => :post do %>
<span class="font-18"><%= key %></span>
<% end %>
<% elsif tags[key] == 2 %>
<%= link_to by_tag_media_path(:tag => key), :remote => true, :method => :post do %>
<span class="font-24"><%= key %></span>
<% end %>
<% elsif tags[key] == 3 %>
<%= link_to by_tag_media_path(:tag => key), :remote => true, :method => :post do %>
<span class="font-36"><%= key %></span>
<% end %>
<% end %>
<% end %>
</p>
這個鏈接是在部分命名_tags.html.erb和索引。 html.erb頁面,是部分呼叫我有這樣的JS代碼:
function apply_filters(load_more){
var params = "";
$("a.selected").each(function(i, obj){
params += $(this).text() + "/"
});
$("a.type_class").each(function(i, obj){
params += $(this).text() + "/";
});
if(load_more){
$.post("/media/filtered", {filters: params, load_more: true});
} else {
$.post("/media/filtered", {filters: params});
}
}
$("#filtered_media_path").click(function(){
apply_filters(true);
});
當這個js代碼被稱爲我重新呈現_tags.html.erb部分和鏈接工作確定(發送POST),但當初始頁面呈現時,他們發送GET請求。兩種情況下渲染後的html代碼都是相同的。
部分類形式的索引頁:
<span id="cards">
<%= render :partial => "media_cards", :locals => {:media_cards => @media_cards, :tags => @tags, :featured_cards => @featured_cards} %>
</span>
和media_cards部分:
<div class="card media-card search hide-for-mobile">
<input type="text" name="search-value" id="search_value"/>
<span id="tags">
<%= render :partial => "tags", :locals => {:tags => tags} %>
</span>
</div>
by_tags.js.erb:
$("#cards").html("<%= escape_javascript(render :partial => 'media_cards', :locals => {:media_cards => @media_cards, :tags => @tags, :featured_cards => @featured_cards}) %>");
生成的HTML看起來像:
<a href="/media/by_tag?tag=test" data-method="delete" data-remote="true" rel="nofollow">
<span class="font-36">test</span>
</a>
你能在routes.rb中顯示已定義的資源嗎? – Doguita