Reputation: 29514
i am using gem 'jeditable-rails' in my rails 3.2 application for inplace editting In my controller, i have
def update
@article = Article.find(params[:id])
@article.update_attributes(params[:article])
render :layout => false if request.xhr?
end
ANd in my articles/update.js.slim
i have
- unless @article.errors.empty?
| $("#error_msg").html(@article.errors);
- else
| $("#success_msg").html("updated successfully");
But when i do an update it updates and going to the js file and renders it like as it is.
like $("#error_msg").html(@comment.errors);
is printed as such or $("#success_msg").html("updated successfully")
EDIT :
i am using the jeditable plugin for edit in place for my article title alone. It updates the article title and renders the js file as it is
the response which i got here is json. how to resolve this. GIve suggestions
Upvotes: 1
Views: 2130
Reputation: 7434
Using the |
pipe tells the Slim rendering engine to output the content as text, hence why you are literally seeing it print your JavaScript code as text.
In this case, I don't think you want or need to use Slim here. Using ERB would be just fine. Try replacing the articles/update.js.slim
file with articles/update.js.erb
instead with the following code:
var valid = <%= @article.errors.empty? %>;
if (valid) {
$("#success_msg").html("updated successfully");
}
else {
$("#error_msg").html("<%= escape_javascript(@article.errors) %>");
}
Upvotes: 1