Basic database question

Hi there
Yes, I know very little of ruby. I must take a crash course?
Probabily.
Anyway, I try to ask this here.

I have a control: customer_controller.
From here, I can do something like:

@id = 1
@customer = Customer.find(id)

Now @customer will contain all the fetched record for customer with id
= 1. Great.

From this controller I will render an html page. Somewhere the view
will print test. SOmething like:

“This is your account”

But I want to fetch this text from the database.
The customer table also have a field named lang.
Having a table called “page_texts” I want from customer_controller,
using the field "lang* for the current customer, fetch all the record
for the customer’s language.

Should I do this from customer_controller? Or is it a bad idea?
Do I need to create the lang_controller?
And how do I, from customer_controller, include the rows from the
language table?
Thanks.

On 9 June 2011 08:06, Sta C. [email protected] wrote:

Hi there
Yes, I know very little of ruby. I must take a crash course?

Work through the rails tutorial at railstutorial.org which is free to
use online. Even though it may appear that this app is not similar to
what you want to write you will learn a great deal.

= 1. Great.
for the customer’s language.

Should I do this from customer_controller? Or is it a bad idea?
Do I need to create the lang_controller?
And how do I, from customer_controller, include the rows from the
language table?

Have a look at the Rails Guide on ActiveRecord relationships ( and the
other guides for that matter). Once you have setup the relationships
properly then you will be able to do things like
@user.page_texts
to give you all the texts for that user

You will probably want a languages table and then something like User
belongs to Language and User has many page_texts through language.

When you have worked through railstutorial.org and made sure you
understand the ActiveRecord relationships guide then ask again if you
are not sure how to proceed.

As a final note, though, if you are doing internationalisation then
there may be better ways to achieve this. Still do the tutorial and
look at the guides first though.

Colin

There are some good books about beginning Rails development - even
some of those geared toward Rails 2 will give you a basic
understanding of the model view controller theory which is Rails.

Don’t be afraid to try things as well, you’ll learn a lot more this
way.

On Jun 9, 9:42am, Colin L. [email protected] wrote:

Work through the rails tutorial at railstutorial.org which is free to
use online. Even though it may appear that this app is not similar to
what you want to write you will learn a great deal.

Thanks I will.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs