ERB
ERB code is basically Ruby
/ Rails
' way of dynamically handling code (like PHP
's <$ $>
). The use of ERB code is basically just about calling methods & classes which utilize the pre-processing power of Rails
To demystify your code, and as stated by @BroiState
, you have several elements to consider:
--
Methods
edit_status_path(status)
This is a Rails method to render a path (which will basically output domain.com/path/to/your/controller
As mentioned, this will be derived from your config/routes.rb
file. However, what I want to express the role methods
play in your code. Every time you call a mysterious
method in Rails, you're basically tapping into the MVC programming pattern - which means you're using the methods available to your view
.
Every piece of ERB functionality is a method
or object
In Rails' case, these are typically known as helper
methods, which can both be explicitly declared (in app/helpers
), or implicitly declared (inside Rails
).
Many of the path helpers will be defined inside the Rails framework, which is why they seem mysterious. However, as you gain more experience, you'll see many different Rails Classes which define many of the mysterious methods - allowing you to gain a more intimate view of how this works
--
Arguments
The famous :symbol
is a ruby module which basically allows you to define a temporary object, ready to be populated with data (I think)
All of the method: :delete
etc - are all arguments for the methods you're using in your views. Every method you use has arguments, and many of them will be symbols.
ERB is basically just a case of using methods & objects, and your :arguments
essentially allow you to use different methods in your views