Has anyone gotten the jquery plugin jeditable to run properly in a Rails applications. If so, could you share some hints on how to set it up? I'm having some trouble with creating the "submit-url".
IIRC, you cannot simply call ruby code from within javascript (please let me be wrong:-). Do you mean RJS??? Isn't that limited to Prototype? I'm using jQuery.
UPDATE:
uh.....asked this a while back and in the meantime switched to a different solution. But IIRC my main issue was the following:
I'm using the RESTful resources. So let's say I have to model a blog and thus have the resource "posts". If I want to edit a post (e.g. the post with the ID 8), my update is sent via HTTP to the URL http://my.url.com/posts/8 with the HTTP verb POST. This URL however is constructed in my Rails code. So how would I get my submit-url into my jQuery code? Since this is RESTful code, my update URL will change with every post.
Here is how I wired up JEditable (1.6.2) with my restful Rails app (2.2.2):
Inline Form:
<div id="email_name"><%= h( @email.name ) %></div>
$('#email_name').editable( <%= email_path(@email).to_json %>, {
name: 'email[name]',
method: 'PUT',
submitdata: {
authenticity_token: <%= form_authenticity_token.to_json %>,
wants: 'name'
}
});
Controller:
def update
@email = Email.find( params[:id] )
@email.update_attributes!( params[:email )
respond_to do |format|
format.js
end
end
update.js.erb
<%=
case params[:wants]
when 'name' then h( @email.name )
# add other attributes if you have more inline forms for this model
else ''
end
%>
It is a bit clunky with that switch statement. It would be nice if JEditable would just save the submitted value by default if the ajax request was successful and nothing was returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With