This looks good. The only problem is that this now object references 
won't work with anything other than ActiveRecord, unless to_param is 
defined. What if it were ref.to_param if to_param is defined and ref.id 
otherwise?

- Nathan

Matt Lyon wrote:
> Hey hamlers,
>
> For various reasons I don't like exposing object ids to the world. 
> Since you can override #to_param in your AR classes (it defaults to 
> aliasing #id) and have that value used in your URIs, I figure that's 
> also a good value to use for dom IDs and such. This does no sanitation 
> of the output of #to_param, but then that value is supposed to be 
> URI-safe, so anyone overriding #to_param should know what they're doing.
>
> Here's the patch. Thoughts?
>
> Index: test/haml/mocks/article.rb
> ===================================================================
> --- test/haml/mocks/article.rb    (revision 563)
> +++ test/haml/mocks/article.rb    (working copy)
> @@ -1,6 +1,6 @@
>  class Article
>    attr_accessor :id, :title, :body
>    def initialize
> -    @id, @title, @body = 1, 'Hello', 'World'
> +    @id, @to_param, @title, @body = 1, 1, 'Hello', 'World'
>    end
>  end
> \ No newline at end of file
> Index: lib/haml/buffer.rb
> ===================================================================
> --- lib/haml/buffer.rb    (revision 563)
> +++ lib/haml/buffer.rb    (working copy)
> @@ -194,7 +194,7 @@
>        # Let's make sure the value isn't nil. If it is, return the 
> default Hash.
>        return {} if ref.nil?
>        class_name = underscore(ref.class)
> -      id = "#{class_name}_#{ ref.id <http://ref.id> || 'new'}"
> +      id = "#{class_name}_#{ref.to_param || 'new'}"
>  
>        {'id' => id, 'class' => class_name}
>      end
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to