If you use “form_for” you may have noticed in Rails 2.0 that there is now a label method to create html label tags: This is great for two reasons:
So instead of doing this:
<%- form_for @post do |f| -%>
<div>
<label for="post_title">Title</label>
<%= f.text_field :title %>
</div>
...
You can now do this! Which will take the method argument (:title) and create the label text (“Title”).
<%- form_for @post do |f| -%>
<div>
<%= f.label :title %>
<%= f.text_field :title %>`
</div>
...
Also, if you have label text that doesn’t quite match the method of your object or maybe you need the string to be translated in a different language. You can do this as well:
<%- form_for @post do |f| -%>
<div>
<%= f.label :title, _('Title') %>
<%= f.text_field :title %>
</div>
...
Sell it you two sexy devils.
this is from last weeks Refresh Phoenix Demo Night - Adam Mollmeyer is the photographer, click through to his flickr page or type in the web address on the photo you lazy bastards. oh, and sign up for nehmehyeh.com
via http://www.flickr.com/photos/acmeextra/2259134825/
1 : the quality or state of being ultimate
2 : the ultimate intimacy
Used in a sentence: Matt has taken intimacy to the next level, ultimacy
For most projects, our controllers tend to have some shared behavior that inherits from a base controller. Such as before filters for authentication or finding an AR model. RSpec also has a similar concept know as “shared behaviors”.
But it’s kind of difficult to do something like:
it 'should redirect to login if not logged in' do
do_post
response.should redirect_to(new_sessions_path)
end
because it might be a do_get, do_put, or do_delete.
do_action let’s you push common controller specs into a shared context without having to specify the exact action being called. add this to your spec_helper.rb
def do_action
%w(get post put delete render).each do |action|
self.send "do_#{action}" if self.respond_to?("do_#{action}")
end
end
And now you can put the previous code in a shared login spec
it 'should redirect to login if not logged in' do
do_action
response.should redirect_to(new_sessions_path)`
end
Matt Gist and myself will be presenting Blueprint a CSS framework at Refresh Phoenix on Nov 6th.
Other resources:
At Ruby Conf 07, Evan Phoenix the project lead for rubini.us gave a great talk about rubini.us vm. The key takeaway for myself, was ability to contribute to the language using the language itself.
What an obvious concept right? Use Ruby to make Ruby. Unfortunately this has not been the case with any implementation the Matz Ruby Implementation(MRI), JRuby, or Iron Ruby using C, Java, and C#, respectively. Most languages need a way to bootstrap itself, but MRI has still not shed it’s shackles of it’s C implementation.
Another concept, that this project has pushed forward with, is that the language should have an executable spec (using a rspec compatible suite). Now if certain aspects of the language seem to behave in a peculiar way, you can now look up the spec and see if ruby code is producing the desired behavior. This will hopefully drive an increase in development towards Ruby.
An aside, while at tbe conference there was a push to define the specification. Even while, most of the core ruby developers are Japanese with limited English.
This was a fun and short (reference to the customer) project that showcases local blogs here in phoenix.
Check it out http://readphoenix.com!