Web Programming examples

Google Maps,AngularJS

Ruby on Rails Tutorial add follower stats to the profile page

1)Rails controller

$ vi app/controllers/users_controller.rb

  def show
    user = User.find(params[:id])
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    microposts = user.microposts
    @user_info = {
      user: user,
      gravatar_url: "https://secure.gravatar.com/avatar/#{gravatar_id}",
      microposts: microposts,
      followed_users: user.followed_users,
      followers:  user.followers
    render json: @user_info

2)AngularJS template view

$ vi app/assets/templates/users/show.html.erb

<div class="col-xs-6 col-sm-4">
    <img alt="{{user_info.user.name}}" src="{{user_info.gravatar_url}}" />
  <div class="stats">
    <a href="#">
      <strong id="following" class="stat">
    <a href="#">
      <strong id="followers" class="stat">

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.