Reputation: 51
My sqlite3 database has contacts of people in the following format:-
id first_name last_name location city country phone_number email
I have filled two entries into the database.
My model class is as follows:-
class Contact < ActiveRecord::Base
# attr_accessible :title, :body
end
My controller is as follows:-
class ContactController < ApplicationController
def index
@contacts=Contact.find(:all)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @contacts }
end
end
def show
@contacts=Contact.find(:all)
end
def new
end
def create
end
def update
end
end
My view is as follows:-
<h1>My Contact List</h1>
<% if @contacts.blank? %>
<p>No contacts to display</p>
<% else %>
<ul id="contacts">
<% @contacts.each do |c| %>
<li>
<% link_to c.first_name + ' ' + c.last_name, :action =>'show', :id =>c.id -%>
</li>
<% end %>
</ul>
<% end %>
When i run start the Webrick server to view localhost:3000/contact/index i just get "My Contact List" with 2 blank list items and not the actual contents from the database.
How should i proceed? I am not able to find out my mistake.
Upvotes: 0
Views: 568
Reputation: 12273
looks like you need to use the equal sign. so in your view do the following
<%= link_to c.first_name + ' ' + c.last_name, :action =>'show', :id =>c.id %>
Upvotes: 1