Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to not displaying anything rails

I am trying to create a hyperlink in the index page but it doesn't show and it doesn't give any errors either.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 have checked my routes and i think they are okay 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 localhost but i don't think thats the problem. Any help is appreciated..

like image 782
soldiershin Avatar asked Dec 07 '14 16:12

soldiershin


1 Answers

The correct syntax to print anchor tag using rails link_to helper is below. You forgot '=' symbol.

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

Ruby code processing within <% %> in 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
like image 186
Dave Avatar answered Sep 29 '22 08:09

Dave