The goal is to render an edit form by calling some sort of $.ajax function in my javascript.
I am using FullCalendar to display some events so I would like to implement something that allows the user to click on an event and render our existing edit form somewhere on the page.
So this is where I'm looking to do it:
// the javascript
eventClick: function(calEvent, jsEvent, view) {
$.ajax({
url: '/course_offerings/'+calEvent.id+'/edit',
});
},
eventClick is essentially a callback after you click an event :)
calEvent.id is a course_offering id
So unfortunately I don't have access to the nice :remote => 'true' options for setting up links.
Here's a few snippits of code:
# controller edit function
@course_offering = CourseOffering.find(params[:id])
respond_to do |format|
format.html
format.js
end
# edit.js.erb, quickedit is the div where I want the form to render
$('#quickedit').append('hi');
Is this the correct way to go about this? I really want to start as simple as possible with the ajax calls, I've been reading some examples and they get pretty complex.
Also the requirements for a jquery $.ajax call in a Rails environment are pretty much a mystery to me.
Edit 1:
Sooo close
I tried the following:
$.ajax({
dataType: 'script',
url: "/course_offerings/1/edit"
});
And in chrome's debugger I got:
http://localhost:3000/course_offerings/1/edit?_=1302199862022 500 (Internal Server Error)
I haven't done any special header setup, so I think that might be the issue
Edit 2
ActionView::Template::Error (Missing partial course_offerings/edit with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, :html], :locale=>[:en, :en]} in view paths "/home/emp/ror/smarssched/app/views", "/home/emp/.rvm/gems/ruby-1.9.2-p136/gems/devise-1.1.5/app/views"):
1: $("#quick_edit").html(<%= escape_javascript(render :partial => 'edit', :object => @course_offering) %>)
I switched the partial to edit after getting an error with :partial => 'course_offering'
To hopefully render the edit partial.
Edit 3
ActionView::Template::Error (undefined method `formats' for nil:NilClass):
1: $("#quick_edit").html(<%= escape_javascript(render :action => 'edit', :object => @course_offering) %>)
app/views/course_offerings/edit.js.erb:1:in `_app_views_course_offerings_edit_js_erb__58426168_85487740_698365018'
app/controllers/course_offerings_controller.rb:48:in `edit'
# Line 46-51 edit function
def edit
@course_offering = CourseOffering.find(params[:id])
respond_to do |format|
format.html
format.js
end
end
If I take the respond_to block out, it throws the same error.
_and are only html fragments.