有人可以描述ERB文件中使用的以下字符的用法:
<% %>
<%= %>
<% -%>
<%# %>
Run Code Online (Sandbox Code Playgroud)
每个人的用法是什么?
我试图在索引页面中创建一个超链接,但它没有显示,它也没有给出任何错误.这是我的index.html.erb代码.
<h1> Listing articles </h1>
<% link_to 'New article', new_article_path %> <---- Everything works perfectly except this doesnt show anything
<table>
<tr>
<th>Title</th>
<th>Textssss</th>
<tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %> </td>
<td><%= article.text %> </td>
</tr>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud)
我检查了我的路线,我认为它们也没关系.
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE …
Run Code Online (Sandbox Code Playgroud) 我对下面关于ERB模板的想法是否正确?任何建议都会非常感激.
嵌入式ruby语法是否具有等号"<%=%>",旨在呈现某些输出?而没有等号"<%%>"的那个没有.