# View not working with . but works with \[' '\]

**URL:** <https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449>\
**Category:** Rails\
**Created:** [March 11, 2007, 8:18am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449 "2007-03-11T08:18:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 8:18am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/1 "2007-03-11T08:18:02Z")

</div>

I have some weird view behavior going around which I am unable to  
understand.

\<% for b in @admin\_budget %\>

 \<%= b['rental'] %\> \<%= b['phone'] %\> \<%= b['consumables'] %\> \<% end %\>

works… but

\<% for b in @admin\_budget %\>

 \<%= b.rental %\> \<%= b.phone %\> \<%= b.consumables %\> \<% end %\>

does not work.

b.inspect throws up  
#“7”, “current\_approval\_status”=\>“N”, “misc”=\>“1000”, “place\_id”=\>nil,  
“updated\_at”=\>“2007-03-11”, “approved\_by”=\>nil, “created\_by”=\>“3”,  
“total”=\>“0”, “updated\_by”=\>nil, “id”=\>“3”, “phone”=\>“1500”,  
“year”=\>“2007”, “salaries”=\>“5000”, “rental”=\>“2500”,  
“approved\_at”=\>nil, “consumables”=\>“1000”,  
“created\_at”=\>“2007-03-11”}\>

and b.class throws up  
AdminBudget

What is happening here? Any clues?

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 8:22am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/2 "2007-03-11T08:22:03Z")

</div>

Quick addition…

Just before the b.rental I am using b.month and b.year and  
b.user.name. They produce the expected results! Wits end, folks.

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 8:43am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/3 "2007-03-11T08:43:05Z")

</div>

K. Rajesh wrote:

> “updated\_at”=\>“2007-03-11”, “approved\_by”=\>nil, “created\_by”=\>“3”,  
> Regards,  
> Rajesh

If you check b.methods what do you see?

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 9:12am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/4 "2007-03-11T09:12:06Z")

</div>

Thats a fairly big list… here goes

[“logger”, “table\_name\_prefix=”, “instance\_values”,  
“update\_attributes”, “save\_with\_validation”, “toggle!”, “after\_save”,  
“build\_user”, “singleton\_methods”, “logger=”,  
“clear\_aggregation\_cache”, “hash”, “send”, “enable\_warnings”,  
“initialize”, “record\_timestamps”, “save!”, “update”,  
“attributes\_before\_type\_cast”, “instance\_of?”,  
“before\_validation\_on\_update”, “nil?”, “record\_timestamps=”,  
“attribute\_names”, “valid?”, “remove\_subclasses\_of”, “instance\_exec”,  
“id\_before\_type\_cast”, “before\_create”, “allow\_concurrency”,  
“create\_user”, “protected\_methods”, “clear\_association\_cache”,  
“silence\_stderr”, “tainted?”, “create\_with\_callbacks”,  
“instance\_eval”, “table\_name\_suffix”, “user”, “allow\_concurrency=”,  
“untaint”, “kind\_of?”, “update\_attribute”,  
“after\_validation\_on\_update”, “equal?”, “save\_without\_validation!”,  
“display”, “table\_name\_suffix=”, “user=”, “blank?”, “load”, “errors”,  
“after\_create”, “destroy”, “private\_methods”, “b64encode”,  
“silence\_stream”, “update\_without\_callbacks”, “readonly!”,  
“set\_place\_target”, “is\_a?”, “freeze”, “attribute\_present?”,  
“before\_destroy”, “increment”, “gem”, “create”,  
“save\_with\_validation!”, “eql?”, “require”, “has\_user?”,  
“before\_update”, “subclasses\_of”, “returning”, “quoted\_id”,  
“update\_attribute\_without\_validation\_skipping”, “id”, “method”,  
“generate\_read\_methods”, “public\_methods”, “lock\_optimistically”,  
“extended\_by”, “`”, “id=”, “attributes”, “update\_with\_callbacks”,  
“generate\_read\_methods=”, “pluralize\_table\_names”, “build\_place”,  
“has\_attribute?”, “after\_destroy”, “extend”, “attributes=”,  
“initialize\_with\_callbacks”, “lock\_optimistically=”, “configurations”,  
“pluralize\_table\_names=”, “user?”, “type”, “after\_update”,  
“with\_options”, “update\_attribute\_with\_validation\_skipping”,  
“object\_id”, “configurations=”, “instance\_variables”, “suppress”,  
“copy\_instance\_variables\_from”, “increment!”, “frozen?”,  
“destroy\_without\_callbacks”, “destroy\_without\_transactions”, “dclone”,  
“create\_place”, “to\_a”, “decrement”, “validate\_on\_create”,  
“create\_without\_timestamps”, “place”, “update\_with\_lock”, “class”,  
“validate”, “before\_validation”, “place=”, “schema\_format”,  
“instance\_variable\_get”, “destroy\_with\_callbacks”, “encode64”,  
“destroy\_with\_transactions”, “verification\_timeout”, “to\_param”,  
“colorize\_logging”, “schema\_format=”, “to\_s”, “validate\_on\_update”,  
“respond\_to\_without\_attributes?”, “new\_record?”,  
“create\_or\_update\_with\_callbacks”, “create\_with\_timestamps”,  
“verification\_timeout=”, “primary\_key\_prefix\_type”,  
“colorize\_logging=”, “reload”, “clone”, “after\_validation”, “to\_json”,  
“to\_yaml”, “instance\_variable\_set”, “primary\_key\_prefix\_type=”,  
“has\_place?”, “==”, “require\_library\_or\_gem”, “===”, “decrement!”,  
“save\_without\_transactions”, “to\_yaml\_properties”,  
“column\_for\_attribute”, “ **id** ”, “to\_xml”, “locking\_enabled?”,  
“to\_yaml\_style”, “inspect”, “toggle”, “decode\_b”, “require\_gem”,  
“valid\_without\_callbacks”, “connection”, “update\_without\_timestamps”,  
“readonly?”, “silence\_warnings”, “respond\_to?”,  
“before\_validation\_on\_create”, “create\_or\_update”, “dup”, “=~”,  
“place?”, “before\_save”, “decode64”, “save\_with\_transactions”,  
“extend\_with\_included\_modules\_from”, “save”,  
“save\_without\_validation”, “ **send** ”, “set\_user\_target”, “taguri”,  
“default\_timezone”, “daemonize”, “[]”, “transaction”, “methods”,  
“[]=”, “update\_with\_timestamps”, “valid\_with\_callbacks”, “taguri=”,  
“table\_name\_prefix”, “default\_timezone=”, “taint”,  
“after\_validation\_on\_create”]

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 9:11am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/5 "2007-03-11T09:11:06Z")

</div>

Few more questions:

- What is b.class.superclass? I assume ActiveRecord::Base?
- Does AdminBudget override rental, phone or consumables with its own  
accessors/methods? If so, you should check into these to make sure  
they’re working correctly.
- What does b.respond\_to?(‘rental’) say? It should return true…

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 9:15am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/6 "2007-03-11T09:15:07Z")

</div>

Mmmm… I had an attr\_reader specified for each of those things…  
when I took it out, things started working again with the . operator.  
Why does this happen?

Rajesh

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 11:39am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/7 "2007-03-11T11:39:29Z")

</div>

Hi,

> Quick addition…
> 
> Just before the b.rental I am using b.month and b.year and  
> b.user.name. They produce the expected results! Wits end, folks.

since rental is not a reserved word either of ruby or AR , I would  
suggest that you do a project-wide (including plugins) of “def rental”  
or “def self.rental” or even better if your search tool allows regular  
expresions “def .\* rental.\*”. That should show you where you are  
overwriting the rental method.

If you are not overwriting it, and assuming your @admin\_budget object  
holds an array of AR objects, then it makes no sense to me, unless you  
have been playing with AR method missing definition.

regards,

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 11:48am UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/8 "2007-03-11T11:48:30Z")

</div>

Because ActiveRecord implements accessors in method\_missing. If you  
actually define a method or accessor with the same name as a column in  
your model, ActiveRecord won’t be able to handle it for you.

Is there a reason you need to specify an attr\_reader for those  
columns?

---

<div class="post-metadata">

**Author:** ![KSRajesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c77e96/32.png) [@KSRajesh](https://www.ruby-forum.com/u/KSRajesh)\
**Post date:** [March 11, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/view-not-working-with-but-works-with/88449/9 "2007-03-11T13:16:37Z")

</div>

No, actually. No reason. I removed it and it works. I was just  
wondering why it didnt work. Learning is (from eden li)

“If you actually define a method or accessor with the same name as a  
column in  
your model, ActiveRecord won’t be able to handle it for you”

Cool,.

Rajesh
