What exactly is f.label and f.text_area referring to here/how is it produced

Stuck on the “saving data” rails lesson: https://www.codecademy.com/courses/learn-rails/lessons/one-model/exercises/one-model-create-messages-i

I’m new to coding and confused by the intro to rails lesson. I’m plugging in the data that the lessons tell me to plug in but they don’t seem to adequately explain to me what exactly I’m doing.

On step 5, the lesson tells us to paste the following into an erb file:

<%= form_for(@message) do |f| %>

<%= f.label :message %>
<%= f.text_area :content %>
<%= f.submit "Create" %>
<% end %>

I was confused as to how exactly this works, as “form_tag” doesn’t get explained very well. What exactly does F represent? It isn’t an instance of message. When I looked at the migration file to see what messages are composed of, text_area and label aren’t listed, so that couldn’t make sense. I’m guessing is maybe they’re HTML stuff? But I’m not sure why that would be called within % brackets. Maybe it’s something built into rails? I can’t find those words anywhere else in the lesson, so I’m not sure what meaning is assigned to them. I mean, this is the problem. A lot of the steps feel very arbitrary. How am I supposed to grasp how these things work if the specifics are never explained?

I haven’t done rails in a long time. But most of this is HTML related. f is an abstraction layer to simplify making a form. f is very likely an object/class which methods to render html.

Writing a form in plain html takes more time. (and more boilerplate code)

the % in the brackets means the no escaping/sanitizing is happening (this way, html is rendered as html and not just plain text).

I would recommend using the official rails documentation along the lessons here on codecademy.

It’s not an object I made, is the problem. Usually with looping, the variable we put in the || signs is something we created. Something.each do |key, value| would make sense in iterating through a hash for example, as ‘key’ and ‘value’ map to the thing. The way ‘f’ is called doesn’t seem to map to the object that it’s being called next to at all.

% is used to input ruby code in an html document, why would html be between <% %> signs?

I’m coming to codeacademy to supplement the docs. But it’s not exactly doing that when there is no effort given towards explaining things. The lesson needs work. So far I’ve encountered multiple bugs and in once case, a step to the lesson was already completed for me when I got to it. I’ve been reporting them. Does anyone actually look at those reports?

the point of using a framework is that a lot code is written for you, so you can speed up your development process. Being able to understand this abstraction and see through it, might take some time to learn.

the form_for function clearly must return something we can loop over.

Ruby needs to know the difference between code which doesn’t need to be rendered (like a loop) and html code that needs to rendered.

codecademy is a teaching platform, when using a framework, the best docs to use are very often the docs of the framework itself.

Yes, the engineers do. We moderators only moderate the forum. So not me.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.