- Clone SwaggerUI project
$ git clone git@github.com:wordnik/swagger-ui.git
- Install nginx (optioinal)
# Get objects older than 3 days. | |
@models = MyModel.where('created_at < :time', { time: 3.days.ago }) | |
@models = MyModel.where(['created_at < ?', 3.days.ago]) | |
# Get objects within the last 3 days. | |
@models = MyModel.where('created_at >= :time', { time: 3.days.ago }) | |
@models = MyModel.where(['created_at >= ?', 3.days.ago]) | |
# Multiple conditions. | |
@models = MyModel.where(['created_at >= ? and name like ?', 3.days.ago, 'Sam%']) |
object = MyModel.create(name: 'Sam') | |
# update_attribute bypass validation but will touch update_at | |
object.update_attribute(:name, 'Yo') | |
object.name == 'Yo' # true | |
object.name_changed? # false | |
# update_column bypass validation but will not touch update_at | |
object.update_column(:name, 'Yo') | |
object.name == 'Yo' # true |
# GET a JSON result. | |
curl -i -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost/sessions.json | |
# POST a JSON result. | |
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" -d '{"id":"IDVALUE","name":"Sam"}' http://localhost/sessions.json | |
# Use cookies (write/read). | |
curl -c cookies.txt -b cookies.txt http://localhost/users.json | |
# Follow redirection. |
# Unique values of a column | |
Address.uniq.pluck(:state) |
# Navigation | |
visit('/resources') | |
visit(resource_path(resource)) | |
# Clicking buttons and hyperlinks | |
click_button('Submit Button') | |
click_link('Link Text') | |
click_link('Link id') | |
click('Link or button') |
# Say you need to run this script which is not part of your Rails app... | |
# Do the following: | |
# | |
# 1. Assume we put this script file in <Rails app root>/tmp | |
# 2. $ cd <Rails app root> | |
# 3. $ rails console | |
# 4. ruby > load "#{Rails.root}/tmp/script_to_run_in_rails.rb" | |
# 5. ruby > MyClass.echo | |
# Hello | |
# => nil |
<%= form_for @my_model, html: { class: 'form-horizontal' } do |f| %> | |
<%= f.label :id, class: 'control-label %> | |
<div class="controls"> | |
<%= f.select(:id, MyModel.all.pluck(:name, :id), include_blank: 'Select') %> | |
</div> | |
<% end %> |
# The mechanism for embedding a notification in a Rails controller is different for render and redirect. | |
def ping1 | |
flash[:error] = 'Warning...' | |
render action: 'pong' | |
end | |
def ping2 | |
redirect_to pong_path, notice: 'Warning...' | |
end |
Add an apt repository and install the logstash-forwarder package.
$ sudo sh -c 'echo "deb http://packages.elasticsearch.org/logstashforwarder/debian stable main" > /etc/apt/sources.list.d/logstash.list'
$ wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install logstash-forwarder