I appreciate that the answer to this question can be complex and include other languages such as jquery,css etc, but i am just looking to get some pointers in the right direction as this is the first time i am trying something this complex
I am building a small recipe app and would like to for example return a link to a recipe and upon clicking take me to the dedicated page for that recipe, but for every recipe, so each recipe will display on a page of its own. This is a very basic example but i can for example return results in a list
<% @desserts.each do |r| %>
<p><%= link_to r.dish_name %></p>
<ul>
<li>Country of Origin <% if r.country %><%= r.country.name %><br></li><% end %>
<li>Category <%= r.category %></li>
<li>Difficulty<%= r.difficulty %></li>
<li>Prep Time<%= r.preperation_time %></li>
<li>Ingredient List<%= ingredient_names(r.ingredients) %></li>
<li>How to prepare<%= preperation_steps(r.preperations) %></li>
<li><%= image_tag r.avatar.url(:thumb)%></li>
</ul>
Does anyone have any resources that could help me, or places i can look for examples. Pointers would be appreciated, just to get me started..
Thank you
Start a new rails app, just for learning some tricks:
Generate a scaffold for an example recipe model (don’t worry that the fields don’t all match your real app – just for learning):
Take note of the files it generates. You’ll want to be able to find the model, views, and controller files again shortly.
Now, migrate the db and run the app:
If you click through and add a few dummy recipes, you should see that the behavior is similar to what you’re asking. There’s a table with a list of recipes, and clicking on links to get to the detailed view and/or the editor for that object.
So, you now have sample code to follow. Look at the simple interactions recipe.rb model file, the recipes_controller.rb file, and the recipes/ directory under views/. Run
rake routesif you’re not sure which controller action or view template corresponds to any given url path.This is pretty fundamental stuff, so if you’re still confused at that point you need to spend some time reading a book on Rails 3 and actually work through its examples.