Forum: Ruby on Rails problem with select_tag and observe_field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3832c46fac01379dfa5b14c60fac8b5c?d=identicon&s=25 Vikas Gholap (vikas)
on 2009-05-27 10:03
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-27 10:38
(Received via mailing list)
On May 27, 9:03 am, Vikas Gholap <rails-mailing-l...@andreas-s.net>
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
3832c46fac01379dfa5b14c60fac8b5c?d=identicon&s=25 Vikas Gholap (vikas)
on 2009-05-27 13:20
Frederick Cheung wrote:
> On May 27, 9:03�am, Vikas Gholap <rails-mailing-l...@andreas-s.net>
> 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
3832c46fac01379dfa5b14c60fac8b5c?d=identicon&s=25 Vikas Gholap (vikas)
on 2009-05-27 13:24
Vikas Gholap wrote:
> Frederick Cheung wrote:
>> On May 27, 9:03�am, Vikas Gholap <rails-mailing-l...@andreas-s.net>
>> 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-27 14:06
(Received via mailing list)
On May 27, 12:24 pm, Vikas Gholap <rails-mailing-l...@andreas-s.net>
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
3832c46fac01379dfa5b14c60fac8b5c?d=identicon&s=25 Vikas Gholap (vikas)
on 2009-05-27 14:35
Frederick Cheung wrote:
> On May 27, 12:24�pm, Vikas Gholap <rails-mailing-l...@andreas-s.net>
> 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
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-05-27 14:43
(Received via mailing list)
> 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
3832c46fac01379dfa5b14c60fac8b5c?d=identicon&s=25 Vikas Gholap (vikas)
on 2009-05-27 15:05
Julian Leviston 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
This topic is locked and can not be replied to.