# Problem with select\_tag and observe\_field

**URL:** <https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905>\
**Category:** Rails\
**Created:** [May 27, 2009, 10:03am UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905 "2009-05-27T10:03:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 10:03am UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/1 "2009-05-27T10:03:39Z")

</div>

Hello All,

I have problem with select\_tag and observe\_field. I get following error

" NoMethodError in Businesses#plan\_pricing

Showing app/views/businesses/\_refresh\_subscription\_types.html.haml where  
line #1 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.collect"

## following is source code

code for “\_plan\_pricing.html.haml”

## = error\_messages\_for :business #plan\_picker - form\_for :business, @business, :url =\> polymorphic\_path(@business), :html =\> {:class =\> ‘MainForm’} do |f| = select\_tag ‘plan\_id’, options\_for\_select(Plan.find(:all).collect {|plan| [plan.title, plan.id] }) = observe\_field(‘plan\_id’, :url =\> {:controller =\> ‘users’, :action =\> :refresh\_subscription\_types }, :update =\> :refresh\_subcription\_types, :with =\> “‘plan\_id=’ + $(‘plan\_id’).value”) %span#refresh\_subcription\_types = render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout =\> ‘false’ %p= submit\_tag :next\_page.l

code for “\_refresh\_subscription\_types.html.haml”

= select\_tag ‘subscription’,  
options\_for\_select(@subscription\_types.collect {|subscription\_type| [  
subscription\_type.title, subscription\_type.id ] })

* * *

code in “controller”

def refresh\_subscription\_types  
@subscription\_types = SubscriptionType.find(:all, :conditions =\>  
{:plan\_id =\> params[:plan\_id]})  
respond\_to do |format|  
format.html {  
render :partial =\> ‘businesses/refresh\_subscription\_types’,  
:layout =\> ‘false’  
}  
end  
end

Here i get “@subscription\_types” object nil , when I render  
“\_plan\_pricing.html.haml” first time.

Please tell me where i am doing wrong.

Thanks,  
Vikas.

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 10:38am UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/2 "2009-05-27T10:38:18Z")

</div>

On May 27, 9:03 am, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Here i get “@subscription\_types” object nil , when I render  
> “\_plan\_pricing.html.haml” first time.
> 
> Please tell me where i am doing wrong.

Does the plan\_pricing action set @subscription\_types to something ?

Fred

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 1:24pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/3 "2009-05-27T13:24:56Z")

</div>

Vikas G. wrote:

> Frederick C. wrote:
> 
> > On May 27, 9:03ï¿½am, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Here i get “@subscription\_types” object nil , when I render  
> > > “\_plan\_pricing.html.haml” first time.
> > > 
> > > Please tell me where i am doing wrong.
> > 
> > Does the plan\_pricing action set @subscription\_types to something ?
> > 
> > Fred
> 
> No I’m not setting @subscription\_types to anything.
> 
> I tried to set @subscription\_types in plan\_pricing action as
> 
> @subscription\_types = SubscriptionType.find(:all)  
> so that it load default all subscription types
> 
> but it throws following error.

* * *

ActionView::MissingTemplate in Businesses#plan\_pricing

Showing app/views/businesses/plan\_pricing.html.haml where line #29  
raised:

## Missing template businesses/\_false.erb in view path F:/sarasaves/app/views:F:/sarasaves/vendor/plugins/community\_engine/app/views:

and line 29 is

= render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout  
=\>  
‘false’

i am not understanding what is this error. And there is no such file by  
name \_false.erb in my businesses view

> Thanks,  
> Vikas

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/4 "2009-05-27T13:20:29Z")

</div>

Frederick C. wrote:

> On May 27, 9:03ï¿½am, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Here i get “@subscription\_types” object nil , when I render  
> > “\_plan\_pricing.html.haml” first time.
> > 
> > Please tell me where i am doing wrong.
> 
> Does the plan\_pricing action set @subscription\_types to something ?
> 
> Fred

No I’m not setting “@subscription\_types” to anything.

I tried to set @subscription\_types in plan\_pricing action as

@subscription\_types = SubscriptionType.find(:all)  
so that it load default all subscription types

but it throws following error.

* * *

ActionView::MissingTemplate in Businesses#plan\_pricing

Showing app/views/businesses/plan\_pricing.html.haml where line #29  
raised:

## Missing template businesses/\_false.erb in view path F:/sarasaves/app/views:F:/sarasaves/vendor/plugins/community\_engine/app/views:

and line 29 is

= render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout =\>  
‘false’

Thanks,  
Vikas

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/5 "2009-05-27T14:06:13Z")

</div>

On May 27, 12:24 pm, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> = render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout  
> =\>  
> ‘false’
> 
> i am not understanding what is this error. And there is no such file by  
> name \_false.erb in my businesses view

You’re telling it to use the layout called false. If you don’t want it  
to use a layout you need to say :layout =\> false (ie the value false  
rather than the string ‘false’)

Fred

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 2:35pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/6 "2009-05-27T14:35:41Z")

</div>

Frederick C. wrote:

> On May 27, 12:24ï¿½pm, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ï¿½= render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout  
> > =\>  
> > ï¿½’false’
> > 
> > i am not understanding what is this error. And there is no such file by  
> > name \_false.erb in my businesses view
> 
> You’re telling it to use the layout called false. If you don’t want it  
> to use a layout you need to say :layout =\> false (ie the value false  
> rather than the string ‘false’)
> 
> Fred

I fixed that syntax error ‘false’ to false but still getting same error

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.collect

for  
= select\_tag ‘subscription’,  
options\_for\_select(@subscription\_types.collect {|subscription\_type| [  
subscription\_type.title, subscription\_type.id ] })

thanks

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/7 "2009-05-27T14:43:57Z")

</div>

> options\_for\_select(@subscription\_types.collect {|subscription\_type| [  
> subscription\_type.title, subscription\_type.id ] })

I think this is something to do with brackets and ruby not being able  
to work out what on earth you’re trying to say.

You have brackets on your inner method, but not your outer method, so  
ruby requires you put brackets all around everything.

This is, at least, my guess.

Try this:

\<%= select\_tag(‘subscription’,  
options\_for\_select(@subscription\_types.collect{|subscription\_type|  
[subscription\_type.title, subscription\_type.id]})) %\>

Julian.

* * *

Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
Last updated 20-May-09 (Rails, Basic Unix)  
Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [May 27, 2009, 3:05pm UTC](https://www.ruby-forum.com/t/problem-with-select-tag-and-observe-field/168905/8 "2009-05-27T15:05:25Z")

</div>

Julian L. wrote:

> > options\_for\_select(@subscription\_types.collect {|subscription\_type| [  
> > subscription\_type.title, subscription\_type.id ] })
> 
> I think this is something to do with brackets and ruby not being able  
> to work out what on earth you’re trying to say.
> 
> You have brackets on your inner method, but not your outer method, so  
> ruby requires you put brackets all around everything.
> 
> This is, at least, my guess.
> 
> Try this:
> 
> \<%= select\_tag(‘subscription’,  
> options\_for\_select(@subscription\_types.collect{|subscription\_type|  
> [subscription\_type.title, subscription\_type.id]})) %\>
> 
> Julian.
> 
> * * *
> 
> Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
> Last updated 20-May-09 (Rails, Basic Unix)  
> Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
> Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)

Hi Julian,  
I tried that also but getting same error, is there any wrong in my code

I write all my related code here again.

* * *

* * *

code for “\_plan\_pricing.html.haml”

## = error\_messages\_for :business #plan\_picker - form\_for :business, @business, :url =\> polymorphic\_path(@business), :html =\> {:class =\> ‘MainForm’} do |f| = select\_tag (‘plan\_id’, options\_for\_select(Plan.find(:all).collect {|plan| [plan.title, plan.id] }) = observe\_field(‘plan\_id’, :url =\> {:controller =\> ‘users’, :action =\> :refresh\_subscription\_types }, :update =\> :refresh\_subcription\_types, :with =\> “‘plan\_id=’ + $(‘plan\_id’).value”) %span#refresh\_subcription\_types = render :partial =\> ‘businesses/refresh\_subscription\_types’, :layout =\> ‘false’ %p= submit\_tag :next\_page.l

code for “\_refresh\_subscription\_types.html.haml”

= select\_tag(‘subscription’,  
options\_for\_select(@subscription\_types.collect {|subscription\_type| [  
subscription\_type.title, subscription\_type.id ] }))

* * *

code in “controller”

def refresh\_subscription\_types  
@subscription\_types = SubscriptionType.find(:all, :conditions =\>  
{:plan\_id =\> params[:plan\_id]})  
respond\_to do |format|  
format.html {  
render :partial =\> ‘businesses/refresh\_subscription\_types’,  
:layout =\> false  
}  
end  
end

def plan\_pricing

# I tried following @subscription\_types = SubscriptionType.find(:all)

also but same error  
# @subscription\_types = SubscriptionType.find(:all)  
@user = current\_user  
@business = Business.new  
render :partial =\> “plan\_pricing”, :layout =\> ‘application’  
end
