views:

49

answers:

1

I am editing some code, and I see the following:

<% hook :login do %>
  <% form_tag user_session_path do  %>
    <p>
      <%= label :user_session, :login, 'Email Address' %><br />
      <%= text_field :user_session, 'login' %>
    </p>
    <p>
      <%= label :user_session, :password, 'Password' %><br />
      <%= password_field :user_session, 'password' %>
    </p>
    <p>
      <label>
        <%= check_box :user_session, :remember_me %>
        <%= label :user_session, :remember_me, 'Remember me' %>
      </label>
    </p>

    <p><%= submit_tag 'Log In' %></p>
  <% end %>

  or <%= link_to 'Create a new account', signup_path %> | <%= link_to 'Forgot Password', new_password_reset_path %>
<% end %>

What does

<% hook :login do %>
  ...
<% end %>

do?

I spent about 5 minutes Googling and found nothing on this subject.

+2  A: 

In a pure Ruby sense, all it's doing is calling a method named hook, supplying it one argument and a block.

And after looking through the Spree soure code, yep, here's the method: http://github.com/railsdog/spree/blob/master/core/app/helpers/hook_helper.rb

Without looking further, it's not obvious what this is used for. I'd imagine it's to add some piece of HTML to the built-in template (re-defining what the login form looks like, in this case).

rspeicher
Ahh, right, a named block called hook. That makes sense. Cool. Blocks are still a bit of a newish concept to me.
Chad Johnson