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 insert_flash | |
content_tag :div, class: 'flash' do | |
flash.each do |name, msg| | |
add_flash name, msg | |
end | |
end | |
end | |
private |
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 create | |
# current_user = User.first | |
if moment_params.empty? | |
render status: 406, nothing: true and return | |
else | |
@moment = current_user.moments.build(moment_params) | |
if @moment.save | |
render "moments/show", status: 201 | |
else | |
render status: 422, nothing: true # We should know about things like this. |
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
= form_for Comment.new do |f| | |
= f.text_area :body | |
= f.button t("button.submit") | |
- @video.comments.reverse.each do |comment| | |
- next unless comment.persisted? | |
%div{class: 'comment', id: "comment_#{comment.id}"} | |
= simple_format comment.body |
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
# Tip: If you name your gist foo.rb it will highlight the code as Ruby. | |
class Account | |
# Two things here. First you never use the reader methods you define here. | |
# You can either refactor the code to use them [see other gist] | |
# or just remove them and keep using the instance variables. | |
# Second, usually Rubyists [we have a name!] group class-level code | |
# like attr_reader or defining constants apart from the method definitions | |
# with newlines. Multiple calls of similar types [like another attr_reader here] | |
# would be back-to-back [no newlines] though. Just a readability thing. | |
attr_reader :name, :balance |
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 Sleigh | |
USERS = { | |
"Santa Claus": "Ho Ho Ho!" | |
} | |
def authenticate(name, password) | |
USERS[name] == password | |
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
'original'.tap do |string| | |
break string unless some_condition | |
string.sub! /.*/, '' | |
string << 'replacement' | |
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
get_values(form_elements_cache, question_element).inject(radio_buttons = "") do |radio_buttons, value_hash| | |
html_options[:id] = "#{id}_#{i += 1}" | |
html_options[:onclick] = select_answer_event if follow_ups | |
codes << {:id => html_options[:id], :code => value_hash[:code]} | |
unless question_element.export_column.blank? | |
cdc_attributes << {:id => html_options[:id], :export_conversion_value_id => value_hash[:export_conversion_value_id]} | |
end | |
selected_code = @object.radio_button_answer.include?(value_hash[:value]) ? value_hash[:code] : "" unless !selected_code.blank? |
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
$ rails console | |
Loading development environment (Rails 4.0.8) | |
irb(main):001:0> DateTime.new 0 | |
=> Thu, 01 Jan 0000 00:00:00 +0000 | |
irb(main):002:0> DateTime.new 1 | |
=> Sat, 01 Jan 0001 00:00:00 +0000 | |
irb(main):003:0> DateTime.new 2 | |
=> Sun, 01 Jan 0002 00:00:00 +0000 | |
irb(main):004:0> DateTime.new 3 | |
=> Mon, 01 Jan 0003 00:00:00 +0000 |
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 body_class(string = nil) | |
[string].tap do |names| | |
# Standard | |
names << controller_name << action_name | |
# App-specific | |
names << 'foo' if foo? # Et cetera | |
end.compact.join ' ' | |
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
#survey_search { | |
&.hide { | |
display: none; | |
} | |
// Other rules | |
} |
OlderNewer