Permalink
Browse files

fix and style error messages t:35m

  • Loading branch information...
Will McNeilly
Will McNeilly committed Sep 21, 2011
1 parent 278be6e commit 61840be39832bf551e717c39c9bd656dfd80d6ef
@@ -7,3 +7,18 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+
+$(function (){
+ //$('#new_link')
+ // .bind("ajax:beforeSend", function(e) {
+ // //console.log("PROGRESS");
+ // })
+ // .bind("ajax:success", function(url){
+ // // console.log("SUCCESS");
+ // })
+ // .bind("ajax:error", function(event, data){
+
+ // // console.log("FAIL");
+
+ // })
+})
@@ -302,3 +302,17 @@ hr { border: solid #ddd; border-width: 1px 0 0; clear: both; margin: 10px 0 30px
}
}
}
+
+.error {
+ background-color: $sqsh-red;
+ color: $sqsh-white;
+ font-size: 16px;
+ padding-top: 10px;
+ padding-bottom: 10px;
+ padding-left: 20px;
+ margin-left:130px;
+ width:680px;
+ margin-top: 20px;
+ font-weight:600;
+
+}
@@ -5,12 +5,12 @@ def create
if @link.save
respond_to do |format|
format.html { redirect_to @link }
- format.js
+ format.js
end
else
respond_to do |format|
format.html { render :new }
- format.js { head :status => 500 }
+ format.js
end
end
end
View
@@ -9,7 +9,7 @@ class Link
@@keys = [:url, :key, :views, :session_id, :created_at]
define_model_callbacks :save
- validates :url, :presence => true, :url => {:allow_nil => true}
+ validates :url, :presence => true, :url => {:allow_nil => true, :message => "This is not a valid URL"}
before_save :generate_key
def generate_key
@@ -1,7 +1,7 @@
<%- if @link.errors.any? -%>
-<%- @link.errors.each do |field, message| -%>
- <strong><%= field.to_s.upcase %></strong> <%= message %>.
-<%- end -%>
+ <%- @link.errors.each do |field, message| -%>
+ <strong><%= field.to_s.upcase %></strong> <%= message %>.
+ <%- end -%>
<%- end -%>
<%= form_for @link, :remote => true do |f| %>
<input type="text" name="link[url]" id="id_url" placeholder="Enter your URL…"/>
@@ -1,4 +1,11 @@
-$('.short-link-container').remove();
-$('#new_link').after("<%= escape_javascript(render(:partial => "short_url")) %>");
-$('.link-table').prepend("<%= escape_javascript(render(:partial => "link", :locals => { :link => @link })) %>");
-$('.short-link-container input').focus().select();
+<%- if(@link.valid?) -%>
+ $('.short-link-container, .error').remove();
+ $('#new_link').after("<%= escape_javascript(render(:partial => "short_url")) %>");
+ $('.link-table').prepend("<%= escape_javascript(render(:partial => "link", :locals => { :link => @link })) %>");
+ $('.short-link-container input').focus().select();
+<%- else -%>
+ <%- @link.errors.each do |field, message| -%>
+ $('#new_link').after('<div class="error"><%= escape_javascript(message) %></div>');
+ <%- end -%>
+
+<%- end -%>

0 comments on commit 61840be

Please sign in to comment.