Why I can't override attr_reader for simple_form?

67 views
Skip to first unread message

Amit Ambardekar

unread,
May 30, 2012, 4:20:40 PM5/30/12
to rubyonra...@googlegroups.com
I have simple problem with overriding attribute readers and seeing same changes appear on simple_form. I have a model and it has some attributes that I want to override with different readers. I did something like following

class CustomerSupplierItem < ActiveRecord:Base

  # it has attribute called pack

  def pack
    "Some overridden value"
  end

end

Now when I use the model in simple_form

<%= simple_form_for @customer_supplier_item do |f| %>
  <%= f.input :pack %>
<% end %>

I do not get "Some overridden value" as value in pack input. I see original pack value without overridden attr_reader.

What is the way to override the attr_reader such that is affects simple_form and similar form helpers?

Regards
Amit

pe medeiros

unread,
May 31, 2012, 10:33:03 AM5/31/12
to rubyonra...@googlegroups.com
it seens like it is a issue within the rails form helper itself

I've tried to do what you described and got the same problem, even by using only form_for @model

But you can always write the the value that you want with input_html

<%= f.input :name,  :input_html => { :value => @model.name } %>

it works, but is not the better way, if I were you I would might consider using a class method that will be responsable to return the value you wanted into the "get method"

2012/5/30 Amit Ambardekar <ami...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/d3abKTt41K4J.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.



--
Pedro Henrique de Souza Medeiros
----------------------------------
Cel: +55 (61) 9197-0993
Email: pedr...@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

The Zen of Python, by Tim Peters


Reply all
Reply to author
Forward
0 new messages