相关疑难解决方法(0)

Rails中ERB中的<%,<%=,<%#和 - %>有什么区别?

有人可以描述ERB文件中使用的以下字符的用法:

<%   %>
<%=  %>
<%  -%>
<%#  %>
Run Code Online (Sandbox Code Playgroud)

每个人的用法是什么?

ruby templates ruby-on-rails erb

351
推荐指数
5
解决办法
10万
查看次数

link_to没有显示任何rails

我试图在索引页面中创建一个超链接,但它没有显示,它也没有给出任何错误.这是我的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)

ruby ruby-on-rails

5
推荐指数
1
解决办法
1099
查看次数

rails中嵌入的ruby语法"<%= ..%>"

我对下面关于ERB模板的想法是否正确?任何建议都会非常感激.

嵌入式ruby语法是否具有等号"<%=%>",旨在呈现某些输出?而没有等号"<%%>"的那个没有.

ruby-on-rails erb

2
推荐指数
1
解决办法
2733
查看次数

标签 统计

ruby-on-rails ×3

erb ×2

ruby ×2

templates ×1