Last active
January 27, 2016 01:46
-
-
Save lasershow/24f097549a75f72b4e48 to your computer and use it in GitHub Desktop.
【Ruby・Rails】三項演算子(条件演算子)を使ってif文をスリムに書こう! ref: http://qiita.com/lasershow/items/160c854e4256ba596ec5
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
def add_button_name | |
if controller.action_name == 'show' | |
"コメントを投稿する" | |
else | |
"コメントを更新する" | |
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
if 条件 | |
式1 | |
else | |
式2 | |
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
条件 ? 式1 : 式2 |
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
def add_button_name | |
if controller.action_name == 'show' | |
"コメントを投稿する" | |
else | |
"コメントを更新する" | |
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
def add_button_name | |
controller.action_name == 'show' ? "コメントを投稿する" : "コメントを更新する" | |
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
def action_name_show? | |
controller.action_name == 'show' ? true : false | |
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
def add_button_name | |
if controller.action_name == 'show' | |
"コメントを投稿する" | |
else | |
"コメントを更新する" | |
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
def add_button_name | |
controller.action_name == 'show' ? "コメントを投稿する" : "コメントを更新する" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment