This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PostsController... | |
def show | |
@post = Post.find params[:id] | |
if params[:id] != @post.to_param | |
headers["Status"] = "301 Moved Permanently" | |
redirect_to post_url(@post) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Post model | |
def to_param | |
sluggify("#{id}-#{location_from}-to-#{location_to}") | |
end | |
def sluggify str | |
slug = str.downcase.gsub(/[^0-9a-z_ -]/i, '') | |
slug = slug.gsub(/\s+/, '-').squeeze('-') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user = new User(); | |
var view = new UserShow({ model: user }); | |
view.render(); | |
$('body').append(view.el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var UserShow = Backbone.View.extend({ | |
initialize: function() { | |
_.bindAll(this, 'render'); | |
}, | |
render: function() { | |
$('#name').html(this.model.get('fullName')) | |
this.fetchTrustCloudInfo(); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var User = Backbone.Model.extend({ | |
defaults: { | |
email: '[email protected]', | |
fullName: 'Robert Pearce' | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderTrustScore: function(user) { | |
$('#trustscore').html(user.trustscore); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderTrustCloudInfo: function(data) { | |
if(data.code === 200) { | |
this.renderTrustScore(data.user) | |
this.renderTrustCloudNetworks(data.user); | |
} else { | |
this.renderTrustCardAbsent(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderTrustCloudNetworks: function(user) { | |
_.each(user.networks, function(item) { | |
var iconHtml = '<li><a target="_new" href="'+item.url+'"><img src="'+item.icon+'" /></a></li>'; | |
$('.badges').append(iconHtml); | |
}); | |
}, | |
renderTrustCardAbsent: function() { | |
$('.badges').append('<li>No TrustCard Found!</li>'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var User = Backbone.Model.extend({ | |
defaults: { | |
email: '[email protected]', | |
} | |
}); | |
var UserShow = Backbone.View.extend({ | |
initialize: function() { | |
_.bindAll(this, 'render'); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchTrustCloudInfo: function() { | |
var self = this; | |
$.ajax({ | |
method: 'get', | |
url: 'https://api.trustcloud.com/profile/getProfile?userid=email-' + this.model.get('email'), | |
dataType: 'json', | |
success: function(data) { | |
self.renderTrustCloudInfo(data); | |
} | |
}); |