Skip to content

Commit

Permalink
update url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelminter committed Sep 19, 2012
1 parent 5bee5e5 commit 593e521
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def cycle_fully_sick

if @fracture.save
if @fracture.update(:encoded_uri => @fracture.id.to_s(36))
{ :fractured_url => "http://fracture.it/#{@fracture.encoded_uri}" }.to_json
{ :fractured_url => "http://fracture.it/#{@fracture.encoded_uri}", :errors => '' }.to_json
end
else
@fracture.errors.each do |e|
Pusher['test_channel'].trigger('errors', { :message => e })
end
{ :fractured_url => '', :error => @fracture.errors.full_messages }.to_json
{ :fractured_url => '', :errors => @fracture.errors.full_messages }.to_json
end
end

Expand Down
1 change: 1 addition & 0 deletions models/fracture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Fracture

has n, :activities

validates_length_of :url, :min => 6
validates_format_of :url, :with => /\./, :message => 'Not a valid URL format'

before :save, :check_url
Expand Down
42 changes: 19 additions & 23 deletions public/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@ $(document).ready(function() {
$(function(){
$('#contact_form').submit(function(e){
e.preventDefault();
var form = $(this);
var post_url = form.attr('action');
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
$('#loader', form).html('<img src="loader.gif" /> Please Wait...');
$.ajax({
type: 'POST',
url: post_url,
data: post_data,
dataType: 'json',
success: function(msg) {
$('#messages small').fadeOut(500);
$('#loader', form).html('<img src="/images/loader.gif" /> Please Wait...');
$.ajax({
type: 'POST',
url: post_url,
data: post_data,
dataType: 'json',
success: function(msg) {
console.log(msg.errors.length);
$('#messages small').fadeOut(500);
setTimeout(function() {
$('#messages small').html(msg.fractured_url).fadeIn(500);
}, 500);
if (msg.errors.length > 0) {
setTimeout(function() {
$('#messages small').html(msg.fractured_url).fadeIn(500);
}, 500);
$('#messages small').html(msg.errors).fadeIn(500)
},500);
}
});
}
});
});
});

//TWITTER SET UP
// getTwitters('tweet', {
// id: 'mothore',//ADD IN YOUR OWN TWITTER ID HERE
// count: 1,
// enableLinks: true,
// ignoreReplies: true,
// clearContents: true,
// template: '<img src="/images/twitterBird.png" alt="Twitter Bird" class="twitterBird" />"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id_str%/">%time%</a>'
// });
});
3 changes: 2 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<h2 class="tagline"><span class="fancy">"</span>Shorten your URLs like a boss. Start typing in the text field below and hit <em>Enter</em>.<span class="fancy">"</span></h2><!--YOUR TAGLINE OR STATEMENT HERE, DELETE h2.tagline:first-letter IN CSS IF NOT USING QUOTE MARKS-->

<div id="messages"><small>We won't send your details to 3rd parties</small></div><!--/#messages-->
<div id="messages"><small>We won't send your details to 3rd parties</small></div>
<div id="errors"><small></small></div>
<form method="post" action="/" id="contact_form">
<input type="text" name="url" id="email" class="email" placeholder="http://" />
<button type="submit" id="submit"><i class="icon-ok icon large"></i></button>
Expand Down
6 changes: 3 additions & 3 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
}
});

channel.bind('errors', function(data) {
$('#messages').html('<small class="error_message">'+data.message+'</small>');
});
// channel.bind('errors', function(data) {
// $('#messages small').html(data.message).fadeIn(500);
// });
});
</script>
</head>
Expand Down

0 comments on commit 593e521

Please sign in to comment.