Hi I am a newbie in rails. I am trying to render the data from the DB and display. I have been almost succeeded but It was not displaying the data as shown in the image below.
Companies List
Name Place
**VIEW**(Click of this is working and navigating nothing is displaying)
ADD New Company
And Here is my controllers code:
class CompaniesController < ApplicationController
def index
@companies = Company.all
end
def show
@companies = Company.find(params[:id])
end
def new
@companies = Company.new
end
def create
@companies = Company.new(params[:Company])
if @companies.save
flash[:success] = "Welcome to skillable"
redirect_to root_url
else
render 'new'
end
end
end
Here is my view code index.html.erb
<h1>Companies List</h1>
<table>
<tr>
<th>Name</th>
<th>Place</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @companies.each do |companies| %>
<tr>
<td><%= companies.name %></td>
<td><%= companies.place %></td>
<td><%= link_to 'VIEW', companies %></td>
<% end %>
</table>
<br />
<%= link_to 'ADD New Company', new_company_path %>
So can anyone tell me what is my problem. why it is not showing. please I am unable to figure out my problem.
@companies.eachloop you are not closing the row. Before the<% end %>tag you should put a</tr>. Could this be it?