Skip to content

Instantly share code, notes, and snippets.

@Hakon
Hakon / _form.html.erb
Created September 5, 2011 07:11 — forked from vjm/_form.html.erb
CRUD Devise Example
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
# this one does NOT work
params[:wine] = {:bulk_price_per_dozen => 50}
@wine = Wine.new(params[:wine])
# this one ALSO does NOT work
@wine = current_seller.wines.build(params[:wine])
# this one does work
@wine = current_seller.wines.build
@wine.attributes = params[:wine]
@Hakon
Hakon / additional notes
Created August 14, 2011 14:49
restrict deleting/updating to signed in users
I have a session variable that is created on login called current_user i can access the company id and user id by calling the following: current_user.company_id and current_user.id
@Hakon
Hakon / env.rb
Created May 20, 2011 13:21
cucumber rail engine dummy testing
require 'rails'
require 'cucumber/rails3/application'
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../spec/dummy/config/environment')
require 'cucumber/rails3/action_controller'
if defined?(ActiveRecord::Base)
def do_something_with_post(post) # what you write as (post) here is the same as |post| in a block
puts post
end
do_something_with_post(1) # will print 1