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..
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With