It's still hard to use the RoR MVC approach

I believe that it should be fair to state what I think I know so far and what I have done:

1) I created the application and completed my first db migration; I know that I have test and production databases. Dev db has a table called "fault."

2) I made a scaffold that created the necessary files.

3) The basic index / update / destroy methods are configured, and I can view the pages.

4) From what I collect, the ActiveRecord class "Wine" automatically inherits properties from the database? Each column is a property, and each row in the wine table represents a potentially created object that is called from the wine_controller script file.

Now the problem is that I want to create a common layout that all controllers use. The only thing that will change will be the page title, possibly some <link> tags in the title, <body> attributes (most likely javascript onload events) and everything that is inside the <body> tag.

I find myself searching for functions that will do what I want (for example, "favicon_link_tag", "stylesheet_link_tag" and "auto_discovery_link_tag" ...), but I cannot find a suitable place to run them! I know this has something to do with my lack of understanding of how things are done / inherited. For example, if I were to declare @pageTitle in application_controller.rb and use @pageTitle in ApplicationHelper, this would not work. Or even using "stylesheet_link_tag" in application_controller.rb throws an error. I just don't get anything.

How does each thing relate to another in terms of chronological performance, scope, etc.?

+3
source share
1 answer

"app/views" "layout". application.html.erb, , .

"application" - , . , , , . Railscast, .

, , , , yield . yield , , - , yield. , "title" . Railscast .

Rails, , , Rails.

" Beginning Rails 3 ", . , , , - . , , .

, , , :)

-EDIT- , :

  1. GET URL.

  2. , , , . : example.com/posts/123?color=red SHOW posts_controller {: color => 'red'} params. params[:color]

  3. , , . , app/<controller_name>/<action_name>, , , (. <action_name>.js.erb AJAX <action_name>.js.erb GET - <action_name>.html.erb.

    • , render, , render 'foo/bar' , FooController, Bar .

    • , , , , , , , , "" .

  4. , . - content_for , content_for , , YIELD application ( , ).

  5. , .

  6. .

, , . , :)

+5

Source: https://habr.com/ru/post/1788633/


All Articles