That's how it worked.
Controller:
def update
if @doctype.update(title: params[:value])
status = msg = 'ok'
else
status = 'error'
msg = @doctype.errors.full_messages.join(',')
end
if request.xhr?
render :json => {
:status => status,
:msg => msg
}
end
end
Html:
<% @doctypes.each do |doctype| %>
<tr>
<td>
<div class="doctype_edit" data-type="text" data-url="/admin/doctypes/<%=doctype.id%>" data-name="title" data-pk=<%= doctype.id %> >
<%= doctype.title%>
</div>
</td>
<td>
<%= link_to '', :id => 'btn_remove_doctype', :data => { :path => admin_doctype_path(doctype), :toggle => 'modal', :target => '#modal_confirm_remove_doctype' }, :class => "btn btn-danger btn-xs" do %>
<span class='glyphicon glyphicon-remove'></span>
<% end %>
</td>
</tr>
<% end %>
Js code:
$.fn.editable.defaults.mode = 'inline';
$.fn.editable.defaults.ajaxOptions = {type: "PATCH"};
$('.doctype_edit').editable({
inputclass: 'inputdoctype',
success: function(response, newValue) {
if(response.status == 'error') {
return response.msg;
} else {
$('this').html(newValue);
}
}
});