V
V
vadimstroganov2015-09-29 01:00:03
Ruby on Rails
vadimstroganov, 2015-09-29 01:00:03

How to get page data?

Hello! I don't understand how it works.
In many projects, for example, to get the page title, page content and any other data, they write like this:

@page.title
@page.content

and so on
All the information comes to the @page variable, it is apparently somehow searched for by the page ID, but I don’t understand how to do the same.
I want me not to write in the controller
@title = sql...
and then pass it to the view, but to immediately write
@page.title
how to do this, please tell me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Burmakin, 2015-09-29
@vadimstroganov

The controller exists for that, to receive data and only after that give it to the view-part. In practice, you can do something like this in the view:
That is, in fact, execute a query to find the desired object directly from the view layer. But this is fu and a sign of complete ignorance (at least because views are not intended for this). Therefore, take for granted the need to receive data in the controller action, assign it to instance variables, and access instance variables in views.
In general, read from cover to cover rusrails.ru , sections "Models", "Views" and "Controllers".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question