On 9 June 2011 08:06, Sta Canovist <[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.

> 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?

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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to