Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The form is not driven that directly by the controllers. Yeah this is the price of all this magic. </p> <p>To clarify a bit: </p> <ul> <li>You type in your browser <a href="http://yourhost/posts" rel="nofollow noreferrer">http://yourhost/posts</a></li> <li>Your request (GET /posts) hits the router, then your router says that the /post urls belongs to the PostsController and the action is index</li> <li>Then your controller executes the index method, do your business logic (loads the posts from the database, for example)</li> <li>loads the view (views/posts/index...) and run it by 'substituting' all the instance variables and stuff defined in your controller (eg @posts = Post.all) that you have in it</li> <li>then you see the view rendered with a list of posts (if in the view you have something similar to @posts.map{|p| p.title}.join(", ") )</li> </ul> <p>yes I know it's not the best /posts view in the world but it's only to grasp the idea</p> <p>The same goes for form, your form tag (for example form_for) gets an instance from the controller (let's say @post) and (in edit mode) gets filled with your Post attributes. Then when you (edit something and) click the submit button it makes a request (by default a PUT to /posts) passing all the values in the form, then your controller gets the (POST) values of the requests (the ones you see in the server log) and makes his work (like saving the post's datas)</p> <p>and because of this in a controller you can use the method</p> <pre><code>render :controller =&gt; :foo, :action =&gt; :bar </code></pre> <p>to render another controller action different from the default one</p> <p>Hope this will be useful!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload