Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Last active December 27, 2015 17:18
Show Gist options
  • Save laspluviosillas/7360706 to your computer and use it in GitHub Desktop.
Save laspluviosillas/7360706 to your computer and use it in GitHub Desktop.
Interview Question #4
module ApplicationHelper
def pretty_user_name
"<span class='pretty'>" + @user.first_name + " " + @user.last_name + "</span>"
end
end
class Comment < ActiveRecord::Base
attr_accessible :name, :active
belongs_to :user
end
# /app/views/users/show.html.erb
<h1> Displaying User: <%= pretty_user_name %></h1>
<% @comments.each do |c| %>
<div class="comment">
<p class='title'><%= c.name %></p>
</div>
<% end %>
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name
has_many :comments
end
class UsersController < ApplicationController
def show
@user = User.find params[:id]
@comments = Comment.where("status = 'active' and user_id = ?", @user.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment