@review.rule_failure_id = params[:violation_id]
@review.user = current_user
@review_comment = ReviewComment.new
- @review_comment.user = current_user
- @review_comment.review = @review
- @review_comment.review_text = "Enter your review here"
+ @review_comment.review_text = ""
render :partial => "form"
end
def create
review = Review.new(params[:review])
review.user = current_user
- # save!
- review.save
- # --> Build?
- #review.review_comments.create(params[:review_comment])
- review_comment = ReviewComment.new(params[:review_comment])
+ review_comment = ReviewComment.new(params[:review_comment])
review_comment.user = current_user
- review_comment.review_id = review.id
- review_comment.save
-
- params[:rule_failure_id] = review.rule_failure_id
- index
+ review.review_comments << review_comment
+ if review.valid?
+ review.save
+ params[:rule_failure_id] = review.rule_failure_id
+ index
+ else
+ @review = review
+ @review_comment = review_comment
+ render :partial => "form"
+ end
end
def create_comment
review_comment = ReviewComment.new(params[:review_comment])
review_comment.user = current_user
- review_comment.save
-
- index
+ if review_comment.valid?
+ review_comment.save
+ index
+ else
+ @review_comment = review_comment
+ @rule_failure_id = params[:rule_failure_id]
+ # TODO Find a way to update the right DIV...
+ render :partial => "form_comment"
+ end
end
end
class Review < ActiveRecord::Base
belongs_to :user
belongs_to :rule_failure
- belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id'
+ belongs_to :resource, :class_name => "Project", :foreign_key => "resource_id"
has_many :review_comments, :order => "created_at", :dependent => :destroy
- validates_presence_of :user
- validates_presence_of :review_type
- validates_presence_of :status
+ validates_presence_of :user, :message => "can't be empty"
+ validates_presence_of :review_type, :message => "can't be empty"
+ validates_presence_of :status, :message => "can't be empty"
end
class ReviewComment < ActiveRecord::Base
belongs_to :user
belongs_to :review
- validates_presence_of :user
- validates_presence_of :review
- validates_length_of :review_text, :minimum => 1, :too_short => "Your review cannot be empty."
+ validates_presence_of :user => "can't be empty"
+ validate :comment_should_not_be_empty
+
+ def comment_should_not_be_empty
+ errors.add("Comment", " cannot be empty") if review_text.strip.blank?
+ end
end
<%= text_area :review_comment, :review_text, :id => "reviewText", :rows => 10 %>
<br/>
<input type="button" name="create_btn" value="Create review"
- onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/create?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), onSuccess:function(request){$('createReviewLink<%= @review.rule_failure_id.to_s -%>').style.display='none';} });">
+ onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>', failure:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/create?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), onSuccess:function(request){$('createReviewLink<%= @review.rule_failure_id.to_s -%>').style.display='none';} });">
<input type="button" name="cancel_btn" value="Cancel"
onclick="new Ajax.Updater({success:'reviewFailure<%= @review.rule_failure_id.to_s -%>'}, '<%= ApplicationController.root_context -%>/reviews/list?rule_failure_id=<%= @review.rule_failure_id.to_s -%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form), }); $('reviewFailure<%= @review.rule_failure_id.to_s -%>').style.display='none';">
+
+ <%= f.error_messages :header_message => "Can't create the review", :message => "", :header_tag => :h3 %>
+
<% end %>
\ No newline at end of file
<br/>
<%= submit_to_remote 'create_btn', 'Add comment',
:url => { :action => 'create_comment', :rule_failure_id => @rule_failure_id },
- :update => { :success => "reviewFailure" + @rule_failure_id.to_s, :failure => "fail" } %>
+ :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %>
<%= submit_to_remote 'cancel_btn', 'Cancel',
- :url => { :action => 'list', :rule_failure_id => @rule_failure_id.to_s },
+ :url => { :action => 'index', :rule_failure_id => @rule_failure_id.to_s },
:update => { :success => "reviewFailure" + @rule_failure_id.to_s } %>
+
+ <%= f.error_messages :header_message => "Can't save the comment", :message => "", :header_tag => :h3%>
+
<% end %>
\ No newline at end of file