Last active
December 27, 2015 17:18
-
-
Save laspluviosillas/7360706 to your computer and use it in GitHub Desktop.
Interview Question #4
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
module ApplicationHelper | |
def pretty_user_name | |
"<span class='pretty'>" + @user.first_name + " " + @user.last_name + "</span>" | |
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
class Comment < ActiveRecord::Base | |
attr_accessible :name, :active | |
belongs_to :user | |
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
# /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 %> |
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
class User < ActiveRecord::Base | |
attr_accessible :first_name, :last_name | |
has_many :comments | |
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
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