Problem with select_tag and observe_field

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.

On May 27, 9:03 am, Vikas G. [email protected]
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

Vikas G. wrote:

Frederick C. wrote:

On May 27, 9:03�am, Vikas G. [email protected]
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

Frederick C. wrote:

On May 27, 9:03�am, Vikas G. [email protected]
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

On May 27, 12:24 pm, Vikas G. [email protected]
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

Frederick C. wrote:

On May 27, 12:24�pm, Vikas G. [email protected]
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

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/
Last updated 20-May-09 (Rails, Basic Unix)
Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r

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/
Last updated 20-May-09 (Rails, Basic Unix)
Blog: http://random8.zenunit.com/
Twitter: 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