I've spent a day spinning my wheels trying to understand how Rails :remote=>true works. The question below seems complicated but I'm trying to understand this simple question with the information I provide:
How can I make an Ajax call that simply renders as JS without using :remote=>true? From my understanding :remote=>true simply generates and handles an AJAX call:
My view looks like this:
- opts in a very complicated way, creates a link with :remote => true. This is omitted for simplicity
.e_list = opts.sort_link(:name) = opts.sort_link(:description) - e_list.each do |e| .entry = link_to(e.name, '#', class: 'select_e', data: {e_id: e.id}) = e.description = paginate e_list, remote: true, params: {search:"j", com_id: com.id}
Gallery.js.erb
$('#com<%= @com.id %>').replaceWith('<%= escape_javascript render(partial: "shared/com", locals: {com: @com}) %>');
My Controller:
def gallery
if params[:com_id]
@com = @s.com.find(params[:com_id])
@com.filter = params
end
if c = @s.com.where(:_type => "Com").first
@current_e = c.entries(@user.app_id).first
@current_e.og_url = view_context.og_url(@current_e)
end
render :text => "foobar" if !@current_e
end
logs, after the user clicks on the pagination links or sort links (the key is those links have :remote => true)
Started GET "super long url" for 127.0.0.1 at 2012-05-04 16:08:42 -0700
Processing by CController#gallery as JS
SO I TRY TO RECREATE THIS WITH AJAX:
$('button.search').live 'click', (e) ->
search = $(e.target).attr('search-term')
success_callback = (results) ->
if results
console.log(results)
update_components(results[0].entry, '.entry')
else
$.ajax(
url: 'super long url that is exactly the same url as above!'
).done ->
return false
MY FAILED RESPONSE THAT DOES NOT RENDER AS JS, YET I THOUGHT :remote => true was simply an ajax call wtf?:
Started GET "super long url identical as the one that renders JS" for 127.0.0.1 at 2012-05-04 16:07:22 -0700
Processing by ContestController#gallery as */*
What is going on? How can I make an Ajax call that simply renders as JS without using :remote=>true?
/screens/4fa02763dc1c82269c0001da/contest/gallery.js?app_row_id=5.... If you want the js from the response to execute in the browser you should need to do something likeeval(response), but i'm just suggesting, I never done it and even know how to eval code of a string in javascript..jsright?