0

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.

1
  • Ensure that you actually have correct records in the database to start. Commented May 4, 2012 at 16:24

1 Answer 1

1

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  %>
Sign up to request clarification or add additional context in comments.

1 Comment

Equal sign was missing indeed.Thank you so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.