Link_to don't show anything rails

I am trying to create a hyperlink on an index page, but it does not appear, and it also does not give any errors. Here is my index.html.erb code.

<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> 

I checked my routes and I think they are ok too.

  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 /articles/:id(.:format) articles#destroy root GET / welcome#index 

I can manually access the article / new from the local host, but I do not think the problem. Any help is appreciated.

+5
source share
1 answer

The following is the correct syntax for printing an anchor tag using link_to helper rails. You have forgotten the "=" symbol.

 <%= link_to 'New article', new_article_path %> 

Processing Ruby code inside <%%> in an ERB template.

 % enables Ruby code processing for lines beginning with % <% Ruby code -- inline with output %> <%= Ruby expression -- replace with result %> <%# comment -- ignored -- useful in testing %> % a line of Ruby code -- treated as <% line %> %% replaced with % if first thing on a line and % processing is used <%% or %%> -- replace with <% or %> respectively 
+8
source

Source: https://habr.com/ru/post/1208533/


All Articles