Struggling to troubleshoot my AJAX call in rails 3, I find myself hopelessly confused. On an index page, there's a table listing objects with detail links. The HAML layout appears as:
%h1
Step 1: Create/upload your CV
#europasslogo
%table.index
%tr
%th.bottom_border= 'CV ID'
%th.bottom_border= 'CV Title'
%th.bottom_border= 'Links'
- @cvs.each do |cv|
%tr
%td.cell= cv.id
%td.cell= cv.name
%td.cell
= link_to 'Matching', match_resume_url(cv.id)
= link_to "Details", cv_path(cv.id), {:remote => true, :method => :get}
.clear
#details
The goal is for the response of clicking the "details" link to be displayed in the #details div at the bottom, simply showing the CV output as plaintext.
In the controller, I've set up the following:
class CvsController < ApplicationController
def new
@cvs = Cv.all
end
def show
cv = Cv.find params[:id]
@data = IO.readlines("public/cvs/#{cv.id}.xml", "").to_s
render :layout => false
end
def match
@cv = Cv.find params[:id]
@language = Language.find_or_create_by_code :en
@vacancies = Vacancy.joins(:vacancy_occupations).where('vacancy_occupations.concept_id' => @cv.occupations.collect{|o| o.id}).uniq
end
end
The server receives and processes the AJAX request when the link is clicked, showcasing the response in Firebug console as well:
Started GET "/cvs/2" for 192.168.33.82 at Fri May 13 00:55:49 -0700 2011
Processing by CvsController#show as JS
Parameters: {"id"=>"2"}
Cv Load (0.1ms) SELECT `cvs`.* FROM `cvs` WHERE `cvs`.`id` = 2 LIMIT 1
Rendered cvs/show.js.haml (2.1ms)
Completed 200 OK in 69ms (Views: 4.3ms | ActiveRecord: 0.1ms)
The AJAX call is successfully received and processed by the server. The show.js.haml file shows:
= "$('details').html(#{@data});"
Despite the large files involved, it seems a lot of generated Javascript code is present. Struggling with limited knowledge in Javascript, I'm puzzled why such a seemingly simple task proves challenging. All I wish for is when the link is clicked, all content within the @data variable integrates into my details section...