Reputation: 5049
Wondering if there is a way to evaluate a snippet of erb code to see the html that it would generate when included in the rails view template without running rails?
for eg. the below erb code snippet
<%= label(:article, 'merge_id', 'Article ID') %>
generates the following html
<label for="article_mergeid">Article ID</label>
Is there a quick way to check the above and other html code generated by erb (or haml) other than running rails and writing the code in view templates? I'm looking for something like irb sorts.
Upvotes: 1
Views: 811
Reputation: 25029
You can use the rails console to run the Ruby code, but it won't parse the ERB for you.
Helper methods (like label
) are available in a rails console via the helper
method, so you can run rails console
and then try:
$ rails console
Loading development environment (Rails 3.2.19)
[1] pry(main)> helper.label(:article, 'merge_id', 'Article ID')
=> "<label for=\"article_merge_id\">Article ID</label>"
Upvotes: 3