I am attempting to update a list of ideas using Ajax, but I keep encountering an unknown format error. The table structure that I am working with can be viewed here: https://i.sstatic.net/agl2R.png
My goal is to sort the table based on a specific filter option. In my home controller, I have the following code snippet:
def sortable
type = params[:type]
case type
when "Recent"
@my_ideas = @my_ideas.ideas.sort_by(&:created_at)
when "Less Price"
@my_ideas = @my_ideas.ideas.order('price asc')
when "Higher Price"
@my_ideas = @my_ideas.ideas.order('price desc')
end
end
Additionally, in my JavaScript file, I have included the following script:
$('#filter_content p').on('click',function(){
$('#filter_content').animate({
height: 0
}).addClass('open');
$('#ideas .item').fadeOut().fadeIn();
var type = $(this).text();
$.ajax({
url: 'home/sortable',
type: 'GET',
data: type,
format: 'js'
})
})
Initially, I tried using a respond_to block in my sortable method with format.js but it did not produce the desired outcome. Would appreciate any helpful hints or suggestions to resolve this issue.