Skip to content

Instantly share code, notes, and snippets.

url call:
"/posts/13"
eager_cache([Posts, :show], :store => :action_store) { self.class.build_request(url(:post, @comment.post), :id => @comment.post.id) }
Doesn't return any errors, but doesn't cache either
irb(main):014:0> u.update_attributes(:password => "test", :password_confirmation => "test")
~ SELECT `id` FROM `users` WHERE (`login` = 'justin') ORDER BY `id` LIMIT 1
=> true
Updating password a no go
irb(main):004:0> u.update_attributes(:password => "test", :password_confirmation => "test")
~ SELECT `id` FROM `users` WHERE (`login` = 'justin') ORDER BY `id` LIMIT 1
=> true
irb(main):005:0>
Updating other attributes works fine
irb(main):007:0> u.update_attributes(:city => "test")
~ SELECT `id` FROM `users` WHERE (`login` = 'justin') ORDER BY `id` LIMIT 1
~ UPDATE `users` SET `city` = 'test', `updated_at` = '2008-11-21 11:06:40' WHERE (`id` = 1)
Merb::Mailer.new(:to => "[email protected]",
:from => "#{email}",
:subject => "#{subject}",
:html => "#{name} sent a message. Category: #{category} -- Message: #{message}").deliver!
@posts = @topic.posts.paginate(:per_page => 25, :page => params[:page], :order => [:created_at.asc]) # Runs an update on posts
@posts = Post.paginate(:per_page => 25, :page => params[:page], :order => [:created_at.asc], :topic_id => @topic.id) # Doesn't run an update on posts
## The first line above calls this on the show action, when it should only run before saving an object
before :save, :white_list
## If the matched image has a "?" as part of the source the gsub fails
## http://example.net/test.jpg <-- Does get gsub'd
## http://example.net/test.jpg?624332 Doesn't get gsub'd
imgs = self.body_html.scan(/\[img\](.*?)\[\/img\]/i)
imgs.each do |img|
body_html.gsub!(/\[img\]#{img[0]}\[\/img\]/i, "<img src=\"#{img[0]}\" />")
end
Problem: With a form_for in Rails 3, it checks object.errors['field'].any?
which in DataMapper returns nil if no errors are found,
in ActiveRecord it returns an empty array.
<% form_for @user, :url => "/users" do |f| %>
<%= f.text_field :login %>
<% end %>
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
Rails 3 + DM 0.10.0
>> User.count
NoMethodError: undefined method `aggregate' for #<DataMapper::Adapters::MysqlAdapter:0xb77b7cc8>
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/repository.rb:5:in `aggregate'
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/aggregate_functions.rb:166:in `aggregate'
from /home/justin/apps/rails/blog/vendor/gems/gems/dm-aggregates-0.10.0/lib/dm-aggregates/aggregate_functions.rb:38:in `count'
from (irb):39
>> User.aggregate
## Controller
def stats
@visits = Visit.all
end
## View that produces 2 sql hits
<%= @visits[0] %>
<% @visits.each do |v| %>
...
<% end %>
class Popup
def make
"Making from instance"
end
def self.make
"Making from class"
end
end