"Undefined method"

23 views
Skip to first unread message

Tim Slattery

unread,
Aug 21, 2012, 4:12:03 PM8/21/12
to rubyonra...@googlegroups.com
I have a controller named RegistriesController. It contains a single
method:

def edit
@jolts_registry = JoltsRegistry.new
end

This runs, and the associated view is invoked. That stops on line 9:

<%= form_for @jolts_registry do |f| %>

The message is:

undefined method `jolts_registries_path' for
#<#<Class:0x184fdd4>:0x1cf7aa0>

What does that mean?

--
Tim Slattery
Slatt...@bls.gov

Walter Lee Davis

unread,
Aug 21, 2012, 4:16:03 PM8/21/12
to rubyonra...@googlegroups.com

On Aug 21, 2012, at 4:12 PM, Tim Slattery wrote:

> I have a controller named RegistriesController. It contains a single
> method:
>
> def edit
> @jolts_registry = JoltsRegistry.new
> end
>
> This runs, and the associated view is invoked. That stops on line 9:
>
> <%= form_for @jolts_registry do |f| %>
>
> The message is:
>
> undefined method `jolts_registries_path' for
> #<#<Class:0x184fdd4>:0x1cf7aa0>

It means you haven't set up a route for it in routes.rb, but you're using one of the route helpers in your view anyway. But have you inspected what this named class is? Is it an instance of your JoltsRegistry model, or maybe nil?

Walter

>
> What does that mean?
>
> --
> Tim Slattery
> Slatt...@bls.gov
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> 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 https://groups.google.com/groups/opt_out.
>
>

Colin Law

unread,
Aug 21, 2012, 4:20:14 PM8/21/12
to rubyonra...@googlegroups.com
Have you put an entry for jolts_registries in routes.rb? Probably
something like
resources :jolts_registries

form_for needs the route to generate the form tag.

Colin

Tim Slattery

unread,
Aug 22, 2012, 8:47:21 AM8/22/12
to rubyonra...@googlegroups.com
I have

match '/registries' => 'registries#edit;

It clearly finds the route, otherwise it wouldn't run the edit method
in registries_controller.

>form_for needs the route to generate the form tag.

Don't understand, which route?

--
Tim Slattery
Slatt...@bls.gov

Colin Law

unread,
Aug 22, 2012, 8:52:08 AM8/22/12
to rubyonra...@googlegroups.com
On 22 August 2012 13:47, Tim Slattery <Slatt...@bls.gov> wrote:
> Colin Law <cla...@googlemail.com> wrote:
>
>>On 21 August 2012 21:12, Tim Slattery <Slatt...@bls.gov> wrote:
>>> I have a controller named RegistriesController. It contains a single
>>> method:
>>>
>>> def edit
>>> @jolts_registry = JoltsRegistry.new
>>> end
>>>
>>> This runs, and the associated view is invoked. That stops on line 9:
>>>
>>> <%= form_for @jolts_registry do |f| %>
>>>
>>> The message is:
>>>
>>> undefined method `jolts_registries_path' for
>>> #<#<Class:0x184fdd4>:0x1cf7aa0>
>>>
>>> What does that mean?
>>
>>Have you put an entry for jolts_registries in routes.rb? Probably
>>something like
>>resources :jolts_registries
>
> I have
>
> match '/registries' => 'registries#edit;
>
> It clearly finds the route, otherwise it wouldn't run the edit method
> in registries_controller.

It is not that route that is the problem

>
>>form_for needs the route to generate the form tag.
>
> Don't understand, which route?

You are trying to create a form for a JoltRegistry, that expects to
submit to a jolts_registries_path (as in the error message). The
normal way to generate the route would be to use
resources :jolts_registries

Have a look at the Rails Guide on Routing if you don't know what that does.

Colin

Tim Slattery

unread,
Aug 22, 2012, 12:38:37 PM8/22/12
to rubyonra...@googlegroups.com
Colin Law <cla...@googlemail.com> wrote:


>> Don't understand, which route?
>
>You are trying to create a form for a JoltRegistry, that expects to
>submit to a jolts_registries_path (as in the error message). The
>normal way to generate the route would be to use
>resources :jolts_registries

I've done that. Same message. I've tried several different
permutations of methods, etc. Always the exact same message. I have no
clue in the world what in the hell it wants me to do. I have no clue
where it gets "jolts_registries" from in the first place.

--
Tim Slattery
Slatt...@bls.gov

Colin Law

unread,
Aug 22, 2012, 12:50:29 PM8/22/12
to rubyonra...@googlegroups.com
In your first post you had
@jolts_registry = JoltsRegistry.new
so @jolts_registry is of JoltsRegistry and hence the route it is looking for.

Did you restart the server after changing routes.rb? That is one of
the few times it is necessary to restart it.
If it is still not working post your routes.rb file, the output from
rake routes
and copy and paste the error message and the section of code it relates to.

Did you read and understand the guide on routing?

Colin

Tim Slattery

unread,
Aug 22, 2012, 4:08:47 PM8/22/12
to rubyonra...@googlegroups.com
Changing the form tag from

<%= form_for @registry do |f| %>

to

<%= form_for @registry, :url => { :action => "create" } do |f| %>

fixed it.

--
Tim Slattery
Slatt...@bls.gov

Colin Law

unread,
Aug 22, 2012, 4:35:48 PM8/22/12
to rubyonra...@googlegroups.com
On 22 August 2012 21:08, Tim Slattery <Slatt...@bls.gov> wrote:
> Tim Slattery <Slatt...@bls.gov> wrote:
>
>>Colin Law <cla...@googlemail.com> wrote:
>>
>>
>>>> Don't understand, which route?
>>>
>>>You are trying to create a form for a JoltRegistry, that expects to
>>>submit to a jolts_registries_path (as in the error message). The
>>>normal way to generate the route would be to use
>>>resources :jolts_registries
>>
>>I've done that. Same message. I've tried several different
>>permutations of methods, etc. Always the exact same message. I have no
>>clue in the world what in the hell it wants me to do. I have no clue
>>where it gets "jolts_registries" from in the first place.
>
> Changing the form tag from
>
> <%= form_for @registry do |f| %>

It was not that in the first place, according to your post it was
<%= form_for @jolts_registry do |f| %>

Colin

>
> to
>
> <%= form_for @registry, :url => { :action => "create" } do |f| %>
>
> fixed it.
>
> --
> Tim Slattery
> Slatt...@bls.gov
>

Tim Slattery

unread,
Aug 23, 2012, 8:47:10 AM8/23/12
to rubyonra...@googlegroups.com
Colin Law <cla...@googlemail.com> wrote:


>It was not that in the first place, according to your post it was
><%= form_for @jolts_registry do |f| %>

ah..Right. I tried a good many things, kept getting the exact same
error until putting the "action" phrase in. yes I looked at the
routing doc. Didn't see anything to help. Still don't get it.

--
Tim Slattery
Slatt...@bls.gov

selv...@gmail.com

unread,
Aug 24, 2012, 6:51:44 AM8/24/12
to rubyonra...@googlegroups.com
It would be more helpful for the people if you post your routes.rb here.



--
Azhagu Selvan

http://tamizhgeek.in
Reply all
Reply to author
Forward
0 new messages