Article:
  Rolling with Ruby on Rails
Subject:   don`t understand action="../update/.."
Date:   2006-10-04 05:11:51
From:   rudyOnTheTrain
hi,
first i`m really new with rubyonrails, so here`s my question.
normaly ror maps the url http://localhost/recipe/list to the folder structur. so i have a folder recipe and a folder list. but in the form tag the action part maps to a folder update"
<form action="../update/<%= @recipe.id %>"

. i can`t find a folder update, so i don`t understand how this part works. can anybody give me a hint?
thx in advance
Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Curt Hibbs photo don`t understand action="../update/.."
    2006-10-04 06:01:56  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

    You are using an incorrect mental model of how things work.

    The "recipe" part of the URL is the is the controller name. This maps to the class named RecipeController which is found in the file app/controllers/recipe_controller.rb. Each controller can have an associated folder that contains view templates for that controller. Hence, you will find an app/views/recipe folder.

    The "list" part of the URL is he action, and that maps to a method in the controller class. If you open the file containing the controller class, you should see a "list" method defined.

    You should *not* have a list folder. Every action can have an associate view template, so what you *should* have is an app/views/recipe/list.rhtml file.

    Now, for the reference to "update". First of all, I should point out that this is not the recommended way to do forms in rails (I was a neophyte myself, when I wrote that). Instead, I should have used the form_tag helper to generate the form tag for me.

    However, this does work, here's what's going on...

    This form is being displayed from a web page with a URL that is somethig like:

    http://localhost:3000/recipe/edit/2

    So the URL on the action attribute of the form tag ends up being something like this:

    "../update/2"

    This is a relative URL, so it results in the browser resolving the URL to:

    http://localhost:3000/recipe/update/2

    This means that it goes to "recipe" controller, and then the "update" method within that controller. You will *not* find a view template for update because it doesn't display anything. It updates he database and then redirects to another URL.

    Unfortunately, if you go look in the recipe controller you will not see an update method, because it is being generated dynamically by the "scaffold :recipe" line. All the other methods are also being generated by the scaffolding, but we have chosen to override them by providing our own definitions.

    Hope that helped... good luck!
    • don`t understand action="../update/.."
      2006-10-04 08:50:20  rudyOnTheTrain [View]

      yes, that help`s me a lot. thank you for explaining me the obviuosly, i was a little bit confused.
      btw a very good tutorial.
      ciao