I was reading the code for the FileColumn, helper and I had a thought. What if we could obviate the need for requiring instance variables for helpers ?

A recent example on the mailing list ? render partial and passing in the object, by Mark Van Holstyn. In the thread, he asks why he can’t do:

1
2
3
4
def edit
  @user = User.find_by_id(1)
  render :partial => 'address', :object => @user.address}
end
His partial being:

<%= text_area('address', 'street') %>
Reading FileColumn helper’s code, and the code in Rails own helpers, the following idiom is used to get a hold of the instance variable:
1
2
3
4
def url_for_file_column(object_name, method, suffix=nil)
  object = instance_variable_get("@#{object_name.to_s}")
  ...
end

What if we did it this way instead ?

1
2
3
4
5
6
7
8
9
def url_for_file_column(object_name, method, suffix=nil)
  object =  case object_name
            when String, Symbol
              instance_variable_get("@#{object_name.to_s}")
            else
              object_name
            end
  ...
end

Actually, this should all be abstracted away in some kind of helper for helpers. Let me take a moment to prepare a patch. I think this would make things quite a bit easier for partial users.

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives