Editing "Tutorials"

Hi, Ive recently bene trying to find a way to edit my tutorials (which
are stored inside categories) in my RoR app. To edit my category's
names I use the following in the category show file:

<%= link_to 'Edit', edit_category_path(@category) %>

And this is edit in the categories controller:

  def edit
    @category = Category.find(params[:id])

but when I change this to tutorials:

<%= link_to 'Edit', edit_tutorial_path(@tutorial) %>


def edit
    @tutorial = Tutorial.find(params[:id])

I get this error on the tutorial show page:

undefined method `edit_tutorial_path' for #<ActionView::Base:

(or something of those origins)

I had the origional category system setup for me, so I dont know that
much about how the categories are editable. Therefore its hard for me
to figure out how to edit the tutorials.

Please Help,

(If you need any more information please just ask),

Thanks In Advance,


What do you mean your tutorials "are stored inside categories?"

Also: rake routes


categories GET /categories(.:format)
                POST /categories(.:format)
new_category GET /categories/new(.:format)
edit_category GET /categories/:id/edit(.:format)
category GET /categories/:id(.:format)
             PUT /categories /categories/:id(.:format)
             DELETE /categories/:id(.:format)
category_tutorials GET /categories/:category_id/tutorials(.:format)
                          POST /categories/:category_id/tutorials
new_category_tutorial GET /categories/:category_id/tutorials/new
edit_category_tutorial GET /categories/:category_id/tutorials/:id/edit
category_tutorial;_tutorial GET /categories/:category_id/tutorials/:id
                           PUT /categories/:category_id/tutorials/:id
DELETE /categories/:category_id/tutorials/:id(.:format)

I think thats the most of the important bit, heres a screen shot of
the console:


Thnks In advance,


Hi Joe,

Then I get this error on the tutorial show page:

edit_category_tutorial_url failed to generate from
{:action=>"edit", :controller=>"tutorials", :category_id=>#<Tutorial
id: 14, category_id: 1, name: "The tutorials name", content: "the
tutorials content", created_at: "2009-09-21 15:55:54", updated_at:
"2009-09-21 15:55:54">}, expected:
{:action=>"edit", :controller=>"tutorials"}, diff:
{:category_id=>#<Tutorial id: 14, category_id: 1, name: "The Tutorial
Name", content: "The tutorials content", created_at: "2009-09-21
15:55:54", updated_at: "2009-09-21 15:55:54">}


(Soz for bump, im just RLLY desperate to fix)

Marnen is right. You're not going to get far with people's help most
places if you don't take the minimal effort to be courteous (or at
least stop using "Soz").

You seem to be desperate rather often (http://groups.google.com/group/
a25e07d2414e2b32/4bca7399878d02d7#4bca7399878d02d7) and feel the need
to bump before 24 hours.

I will tell you, there is a way to evaluate / display the path you're
trying to use using script/console. You should also read this:


Yes correct I am desperate rather often as I was supposed to only take
my site down for a few says to do this and it hs extended onto weeks.

I will read the link (although im so bas in RoR im not honestly sure
if i'll understand it),

If anyone wants to give a more direct answer please feel free to do
so, as the chances are I havnt been able to figure it out.



Strangely.. I acctually figured out what was wrong and corrected to:
edit_category_tutorial_path(@tutorial_category.id, @tutorial)

which seems to lead to the edit page. However I now have an issue on
this page, as the form as it was ( <% form_for(@tutorial) do |f| %> )
gives the error:

undefined method `tutorial_path'

So I decided logically to change it to: <% form_for
(@tutorial_category.id, @tutorial) do |f| %>

which gave a fixnum error, which I read was because I used ".id"
which is a fixed integer so i changed it to:

<% form_for(@tutorial_category, @tutorial) do |f| %>

which now gives me the error I cant solve:

undefined method `nil_class_path' for #<ActionView::Base:0x60caf34>

(or something of those origins)

Please Help me solve this issue, and sorry for my permanent bumping
and this time I shall wait until I decide to bump (if I decide to bump

Thanks In Advance,


Right.. Just maybe figured out another bit of it. I changed:

<% form_for(@tutorial_category, @tutorial) do |f| %>


<% form_for(@tutorial.category, @tutorial) do |f| %>

and this seems to function properly, however now I have a new issue
that ive been working on for hours and still cant figure out how to
In the form the category part of it is like this:

<%= f.label :category_id %><br />
    <%= f.text_field :category_id %>

The first label line works fine but I get this error for the next

undefined method `category_id' for #<Category:0x5fefc2c>

(or something like that)

Ive tried every possible combination I can think of with changing
category_id all the way to things like tutorial.category_id and

So this is the first error I cant solve, so i decided to try without
it and see if the other features work, well :name seems to work fine,
but the next bit (:content) dosn't work.

At the moment its like this:

<%= f.label :content %><br />
    <%= f.text_area :content %>

once again I get the error for the second of the two lines.

And this is my second problem that I cant fix, I havnt tried
without :content and without :category_id yet so im not sure if the
update button works, but I tink these problems should be dealt with


and Thanks In Advance,


I know you've moved on from the path issue, but to help you in the
future, I found something that has helped me figure out paths. One,
someone already mentioned, which was:

:; rake routes

Which you probably already knew. But you can also put a path in that
you're guessing will work and see what the actual URL it converts it
to at runtime:

:; ruby script/console
:; >> include ActionController::UrlWriter
:; => Object
:; >> sessions_path
:; => "/sessions"

Also, there are lots of cool helpers / tricks you can use in Rails,
like the *_path helper, but I've made the mistake of trying to make
some of them work during a tight deadline or when there's high
pressure (site down). If this path or url_for thing is giving you
issues, you can put in an old school :controller =>
'mycontroller', :action => 'myaction' to resolve it.

If you're getting undefined method errors in your form, it's because
the "f" is representing an object that doesn't have methods for the
field you're trying to use. Go to this site: http://railsbrain.com/
View the doc for your rails version and look up: form_for I
downloaded and use this site for my dev... it's extremely helpful.

You're not using form_for correctly. Here are the parameters it

form_for(record_or_name_or_array, *args, &proc)

So, it's using the first one, "@tutorial.category" for the main
object. Do you have a "content" column in Category? Are you trying
to edit Category or tutorial? The error you're getting shows it's
using a Category object:

undefined method `category_id' for #<Category:0x5fefc2c>

for #<Category:0x5fefc2c> indicates it's using a Category object.
Check out the API and use that when you're not positive about the
usage. It's definitely worth the read, especially in very busy times.


Im attempting to edit the tutorial and the tutorial does have content
and name, not the category.

Are the other content bits messing up because i havnt done the form
correctly then?

If so do you have a more direct response to fix it? as im really not
good in rails...

Thanks In Advance,


If you're not good in rails, why are you doing a website in it? Why
are you posting here? Probably to get better, right? Or is it just
to have us fix your site. The info I'm giving you is to help *you*
solve your problem. It's not my problem, and not the problem of this
forum. People that post help here are here to help others that want
to help themselves learn, not get the helpfulness of this forum to
build or fix your app post by post. You're turning help away when you
skate past my links and references and such and just want a *direct*

It's frustrating. If anyone gives you a direct answer, you'll
undoubtedly be back with another desperate request insisting on it
being written out for you word-by-word.


Well of couse im learning from it, and that is for sure. But I really
need to fix this before the big part of the learning curve. I do want
a more direct answer as personally although direct answer may be
classed as "cheating" or "making you do it for me" its the way I find
it best to learn.

I am still reading through the links you gave but really I cant make
much sense of it, and im sorry if im a complete idiot, but its really
not my fault. Im open to learning but personally I dont learn by
reading pages of text cluttered with jargon that I dont understand.


Please Help,


> I do want
> a more direct answer as personally although direct answer may be
> classed as "cheating" or "making you do it for me" its the way I find
> it best to learn.

Well, it's not the way most people on this list find it best to teach.

Hmm... OK.

This thing is with the post above. I dont want to learn massive
ammounts of ruby on rails, I just basically want to make my site in it
(although as you said this is a very difficult task if you dont know
much RoR) but I had someone to help me through the first half and I
ended up learning a whole lot, I never even knew how to create a rails
app before, and now I know a basic ammount, and I know sort off how my
whole system works. I fixed most of the errors etc, while my friend
would just do the main parts for me. Then the problem arrised just at
the last moment before we had incorporated the edit or destroy
functions. I managed to create the destroy function as it was very
similar to the category destroy function, but the edit seems much more
difficult to fix.

I will spend some more time looking through articles about this, and
will look through some basics too.

If anyone has any suggestions or tips to help me through this then
please post,

Thanks In Advance,


You say 'my site'. Can you give us some more background into what the
site is for. Is it a commercial endeavour?


Have a look for yourself http://www.dev-hq.co.uk

Its at the moment what would be classed as a "hobby site" but I plan
to grow it into a profitable buissness in time.

Once again please help,

Thanks In Advance,


Well there is the problem, or at least part of it. If you had been
struggling to complete a site for a worthy non-profit making
organisation then it would be valid to throw yourself on the mercy of
the list and hope that someone might spend their time walking you
through your problems. As this is not the case, however, then all you
should hope for is pointers as to where you are going wrong and where
to go to educate yourself so that you can work out the detail of the
solution yourself.


Hmm. ok, I suppose you have a vailid point.

I will look through many articles and post back if I find a solution
(for anyone else who encounters this problem)

I had to write a new path in routes.rb, it waas that simple. Fixed it
all by myself and I feel good that I did it on my own!

Thanks anyway guys,