Last active
December 28, 2015 16:19
-
-
Save suzukimilanpaak/7527963 to your computer and use it in GitHub Desktop.
my lecture on 18th Nov.
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 Human # => design | |
def say_hello(name) | |
'hello' + name | |
end | |
end | |
@human = Human.new # instance | |
@human.say_hello('David') | |
#=> 'hello David' | |
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 | |
before_filter :ensure_login | |
def show | |
@main_displays = MainDisplay.limit(10) | |
@main_displays.remain_more_than!(0.1) | |
end | |
private # Put the following code into ApplicationController | |
def ensure_login | |
@login_user = User.find(params[:user_id] | |
unless @login_user.present? | |
redirect_to login_path | |
end | |
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
# helper | |
def message_if_no_record(displays) | |
if displays.count == 0 | |
'No display found.' | |
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
# model | |
def remain_more_than!(rate) | |
@main_displays.select! {|main_display| main_diplay.rate > rate } | |
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
%table | |
= message_if_no_record(@main_displays) | |
- @main_displays.each do |main_display| | |
%tr | |
%td | |
= main_diplay.tile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment