Я хочу сериализации вновь созданный ресурс в этой акции:ActiveModelSerializer не ногами в
def create
@comment = @commentable.comments.build(comment_params)
@comment.user = current_user
respond_to do |format|
if @comment.save
format.json { render json: @comment }
format.html { redirect_to @question, notice: "Comment successfully created." }
else
format.html { render 'questions/show' }
end
end
end
Но render json: @comment
возвращает полный объект, хотя в моем CommentSerializer у меня есть:
class CommentSerializer < ActiveModel::Serializer
attributes :id
end
я создаю новый ресурс через ajax:
handleSubmit: function(e){
e.preventDefault();
$.ajax({
context: this,
method: 'POST',
url: "https://stackoverflow.com/questions/" + this.props.question_id + "/comments",
data: {comment: this.state},
success: function(data){
this.props.handleNewComment(data);
this.setState(this.getInitialState);
}
});
},
Что мне здесь не хватает?
Запрос направляется только в порядке, ответ не сериализовано, так что это не причина. –