Posted by Dan Sosedoff
on November 24, 2010
Since i switched to Rails 3 i figured out that you dont need to escape html contents (using h method in Rails 2), its been done automatically. So, for now if you have any plugins or methods that produce raw html you have to use method “html_safe” to unescape it.
Before:
<%= your_helper_method %>
Now:
# your helper method
def your_helper_method
# .... content generation
return content.html_safe
end
In in view:
<%= your_helper_method %>
Posted by Dan Sosedoff
on November 15, 2010
Authlogic is a good authentication library for Rails, supports a lot of different methods. But its not fully compatible with Rails 3 which is solvable. This solution works for latest gem version (2.1.6):
Basically, default setup is the same, nothing specific;
class UserSession < Authlogic::Session::Base ; end
And you’ll probably get error message like this:
undefined method `to_key’ for <UserSession: no credentials provided>
In this case all you have to do is to define additional method in your UserSession model:
class UserSession < Authlogic::Session::Base
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
end
And everything should work just fine.
Posted by Dan Sosedoff
on November 05, 2010
Need to troubleshoot email output? No problem. Just need to configure your development environment with the following lines:
# RAILS_ROOT/config/environments/development.rb
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {:location => "/usr/bin/fake-sendmail.sh"}
config.action_mailer.default_url_options = { :host => "YOUR HOST" }
And here is the fake-sendmail utility i wrote: (save as “/usr/bin/fake-sendmail.sh”)
#!/usr/bin/ruby
dir = "/tmp/fake-sendmail"
headers = ''; $stdin.each_line { |l| headers << l ; break if l.strip.length == 0 }
body = '' ; $stdin.each_line { |l| body << l }
format = body.match(/html/i) ? "html" : "txt"
filename = Time.now.to_i
Dir.mkdir(dir) unless File.exists?(dir)
File.open("#{dir}/#{filename}_headers.txt", "w") { |f| f.write(headers) }
File.open("#{dir}/#{filename}.#{format}", "w") { |f| f.write(body) }
Paste: http://pastie.org/private/er61gafxb6fzowjo4chjvq
As the result you’ll see 2 files created for each outgoing email. One has all email headers and another one has the body.
Also, it works for Sinatra and Merb. Woot!