用Rails重新加载Ajax页面
I new in rails, and i can't understand how to rewrite next functionality.
For example: I have a list of products. And every product has some field ( category )
def index
if params[:select_query]
@posts = Post.selecting(params[:select_query])
else
@posts = Post.all
end
respond_to do |format|
format.html # index.html.erb
format.js
end
end
Index.html
<%= select_tag "credit_card", options_for_select([["first", 1], ["second", 2], ["third", 3]], 2) %>
<div class='tab'>
<%= render 'table' %>
</div>
<%= link_to 'Select', posts_path(select_query: 'first'), class: 'link', remote: true %>
Index.js.erb
$('.tab').html("<%= j render 'table' %>")
JS
$(function(){
$('#credit_card').on('change', function(){
variable = $(this).find('option:selected').text();
$('.link').attr('href', '/posts?select_query='+variable).click();
});
});
I try to realise same functionality but without additional link ( button )
In perfect way i should have only JS file ( with Ajax )
Could help me rewrite this functionality by ajax.
weixin_33712987
2013/07/02 16:13- ruby-on-rails
- ajax
- 点赞
- 收藏
- 回答
2个回复
