Skip to content

Instantly share code, notes, and snippets.

Creating a Multi Page Form in Rails
Creating a multi-step wizard-like form is pretty difficult in Rails.
Especially when trying to apply REST and validations. There are many
different approaches to this problem, and the right one depends largely
on your application details. Here are four options, and then my final
recommendation. Skip to that if you're in a hurry.
1. Create the model at the beginning on the first page of the form, and
have each successive page update the model. Validations are tricky
@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <[email protected]>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@danott
danott / boilerplate.rb
Created December 16, 2011 23:06
Ruby Command Line Utility Boilerplate
#!/usr/local/bin/ruby
puts "Running application"
class App
def initialize(args)
end
def action(input)
"input was #{input}"
@chetan
chetan / yardoc_cheatsheet.md
Last active November 11, 2024 08:27
YARD cheatsheet
@amir20
amir20 / to_csv.rb
Created March 15, 2012 01:10
Converts YAML to CSV
#!/usr/bin/ruby
if ARGV.size.zero?
puts %Q[
Usage:
./to_csv.rb file.yml > out.csv
]
exit
end
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@HTMLsauce
HTMLsauce / TODO - TODO.sublime-snippet
Created December 10, 2012 13:49
Sublime Snippet: TODO - TODO
<snippet>
<content><![CDATA[
<!-- TODO: ${1:message} -->
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>to</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
@pwc3
pwc3 / Exchange Sync.applescript
Last active February 1, 2024 12:34
AppleScript to copy all of the events from an Exchange calendar to an iCloud calendar.
tell application "Calendar"
-- delete everything from the destination calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
repeat with anEvent in (get events of calendar "Destination Calendar")
delete anEvent
end repeat
-- copy all events from the source calendar to the destination
-- TODO: Change "Source Calendar" to be the name of your source calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
@iwan
iwan / multiple_action_on_index.md
Last active December 27, 2015 00:09
Get multiple checkboxes in a index view

Routes file (routes.rb):

resources :data_loaders do
  collection do
    delete 'multiple_destroy'
  end
end

The controller:

@slindberg
slindberg / ember-data.dependent-relations.js
Last active November 5, 2021 21:41
Dependent Relationships in Ember Data
/**
Ember Data: Dependent Relationships
This package extends Ember Data to support creating relationships
where a model's dirty state depends not only on its own attributes
but on the dirty state of models in dependent relationships as well.
```javascript
App.Thing = DS.Model.extend({
name : DS.attr('string'),