So you should have a database table named “contents”.
Then in your controller:
def show_intro
@intro = Content.find(1)
end
In show_intro.rhtml:
<%= @intro.description %>
This assumes there is a column in your “contents” table called
“description”. And you can leave your model “Content” completly virgin.
You can test to see if it worked by just going to
“http://domain.com/my_controller/show_intro” and you should see your
text from the database.
Although you may want to start out without the AJAX thing, until you
have the basics down. It can make things much more complicated.
Alternatively if you still wanted “Content.intro_text” (lowercase with
underscores for method name is the standard ruby convention) to work:
def Content < ActiveRecord::Base
def self.intro_text
find(1).description
end
end
Then in any .rhtml file:
<%= Content.intro_text %>
Remember that “Content.find(1)” returns an entire row as an ActiveRecord
object. To access a specific field, just call it as a method to return
its value:
@content = Content.find(1)
@content.description #=> displays the description for row with id=1
Tim wrote:
Sorry. To explain further, here’s what I tried to do:
This is the line of code in my index.rhtml:
<%= link_to_remote(“Click Here”, :update => ‘introduce’, :url => {
:action => :show_intro }, :complete => visual_effect(:blind_down,
‘introduce’) ) %>
It’s a link to simply display a block of text taken from the database.
In my Controller:
def show_intro
@intro = Content.introText
end
In my Model:
def self.introText
find(1)
end
Where 1 is the ID for the table row. There are 3 fields in my table: id,
title and description.
I’m trying to get the text from the ‘description’ to display above.