2014-12-07 3 views
5

Я пытаюсь создать гиперссылку на странице индекса, но она не отображается, и она также не дает никаких ошибок. Вот мой код index.html.erb.link_to не отображает ничего рельсов

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

Я проверил свои маршруты, и я думаю, что они тоже в порядке.

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 

Я могу вручную получить доступ к статье/новому из локального хоста, но я не думаю, что проблема. Любая помощь приветствуется.

+3

добавить '=' в 'link_to'. '<% = link_to 'Новая статья', new_article_path%>' и читаем о ['ERB'] (http://stackoverflow.com/questions/3952403/without-equal-in-ruby-erb-means) –

+0

Спасибо, чувак что прояснилось много вещей .. – soldiershin

ответ

8

Правильный синтаксис для печати метки привязки с использованием рельсов link_to helper представлен ниже. Вы забыли символ «=».

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

рубин обработки кода в <%%> в шаблоне ERB.

% 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 
+0

Спасибо, я чувствую себя настолько глупо :( – soldiershin

Смежные вопросы