I’ve been holding back this release so I could get distributed routing into it, but it appears that there’s still a little more work that needs to be done before it’s ready to go. I’m hoping to get it out by the beginning of next week, but don’t quote me on that.
Instead of focusing on what didn’t make it in, let’s talk about what did make it in! There’s some cool stuff in this release.
/posts - will render app/views/posts/index.html.erb /posts.html - will also render app/views/posts/index.html.erb /posts.xml - will render app/views/posts/index.xml.erb - A special note .xml.erb files, despite their name, do NOT get run through ERB, instead they use the XML Builder library /posts.js - will render app/views/posts/index.js.erb etc…
Alternatively, in your action you can now define ‘want’ blocks, to run specific code based on the format. Example:
class PostsController
def index
# find all the posts in the system
@posts = Post.find(:all)
wants(:html) do
# this will only be run if html is requested.
# we need a username for a 'welcome message in the view'
@username = @user.username
end
wants(:xml) do
# this will only be run if html is requested.
# find the last published date
@last_pub_date = Rss.find_last_by_date_by_object(:posts)
end
end
end At the very simple level you can easily do this in your code:
@my_encrypted_value = _encrypt("hello world") and you’ll be returned a nice pieced of garbled data using the Crypt/Rijndael library. Decrypting is just as easy: _decrypt(@my_encrypted_value) # => "hello world"See, I told you it couldn’t be easier. It gets even better you can even define your own ‘worker’ to implement other encryption schemes. It’s as simple as this:
REXML could not parse this XML/HTML:
<pre>class Mack::Utils::Crypt::HorribleWorker
def encrypt(value)
value.reverse
end
def decrypt(value)
value.reverse
end
end
encrypt(“hello”, :horrible) # => “olleh”decrypt(“decrypt”, :horrible) # => “hello”</pre> See how easy that was? You can also do:
@my_encrypted_value = "Hello".encrypt @my_encrypted_value.decrypt #=> "Hello"Either way it’s now easy to handle encryption in your funky cool Mack app.
Changelog: