Skip to content

Instantly share code, notes, and snippets.

@arjan0307
arjan0307 / routes
Created May 17, 2012 15:24
Nested routes without parent routes
# How to get just the comment routes, and not the post routes
resources :posts do
resources :comments
end
@posts = @profile.posts # []
@profile.posts.build
@posts # array containing a single post
@arjan0307
arjan0307 / devise.rb
Created April 4, 2012 14:19
E-mails with empty bodies, by devise
# config/initializers/devise.rb
config.mailer = DeviseMailer
@arjan0307
arjan0307 / conversation.rb
Created March 20, 2012 15:29
Nested forms
class Conversation < ActiveRecord::Base
has_many :messages
has_many :participants
has_many :users, :through => :participants
accepts_nested_attributes_for :messages
end
<% if @post.errors.any? %>
var errors = '';
<% @comment.errors.full_messages.each do |error| %>
errors.append("<%= escape_javascript( error ) %>\n");
<% end %>
alert(errors);
<% else %>
$('#posts').prepend('<%=j render 'chapters/posts/post', {:post => @post} %>')
<% end %>
<% if @post.errors.any? %>
var errors = '';
<% @comment.errors.full_messages.each do |error| %>
errors.append("<%= escape_javascript( error ) %>\n");
<% end %>
alert(errors);
<% else %>
$('#posts').prepend('<%=j render 'chapters/posts/post', {:post => @post} %>')
<% end %>