help in making a function inherited by all views

I already asked it in the railsforum.com but it didn't quite got
answered yet so instead of repeating the question heres a link:
http://railsforum.com/viewtopic.php?id=40810
feel free answering either here or in the forums.

explain what you want to achieve becuase what you are doing is confusing.

What happens the most to rails beginners is that we over complicate, becuase we are used to complicated stuff in other frameworks and
can believe that doing thing a simplified as rails does it would work, it appears this is happening in this case since what i thing you are trying to achieve is so easy if done the right way.

I try to make a table in the database where all my texts are in so i
could add another column one day for a different language so when I do
decide to translate my site to a different site it would be a matter
of adding a column to a table.
(BTW I intend to put all the data in my site in the database(with no
real static content so it seems like the best choice i have)

TEREN wrote:

I try to make a table in the database where all my texts are in so i
could add another column one day for a different language so when I do
decide to translate my site to a different site it would be a matter
of adding a column to a table.
(BTW I intend to put all the data in my site in the database(with no
real static content so it seems like the best choice i have)

I believe what you are really trying to ask here is how to properly add
localization to your site. Right now your site is being localized for a
specific language and parts of your site inherit text that is stored in
a specific localization table for say.. English. Then, at another point
in time, you want to be able to add another column for say.. German,
etc.

Is this what you are trying to accomplish?

if you want a variable db schema go with mongodb , but i dont think thats what you really want, i think is easier to have a polimorphic text table that can belong to the models that contain text and pull depending on the locale.

watch a schema less database here

http://railscasts.com/episodes/194-mongodb-and-mongomapper

first of all
Alpha blue, thats exactly what i want.any ideas on how to do this?
and radhames brito, i didnt understand a thing from your comment. could you explain a little more what do you think i need to do?

Almog Friedman wrote:

first of all
Alpha blue, thats exactly what i want.any ideas on how to do this?
and radhames brito, i didnt understand a thing from your comment. could
you
explain a little more what do you think i need to do?

You might want to start here:

http://github.com/defunkt/gibberish

the problem with that way is that it is intended for an application which receives most of its data as user content and the static content of the page(what i control of) is by the most parts isn’t much. most of it is titles and headlines and maybe some explanations of things.

this is not the case with my app.
with my app i am the provider of most of the data, the user only interacts with it. im talking about hundreds upon hundreds of lines of content all made by me. i don’t want to edit this entire data by hand,

i want to use a database. which is why i got to my method as described in my vary first post. with a simple form with which i could insert the data to the database at ease.

now as i ran out of options, could you please help me figure out where should i put this method i did so i would still follow the DRY principle and use MVC correctly?

you said you wanted to add more laguages with time, mongodb lets you at columns to a table on the fly, like this,

lets say you have a table called Content with a column for each language but right now you have 2 languages, english and italian
with mongodb you just say , content.german = “…”, with mongodb and from then on the table has a german field no migrations needed.

at this are the columns

content
id> owner_type| owner_id | english| italian |

then one day you say

article.content.german = “blah blah”

then on the fly from that day on the table turn to this without the need for migrations

content
id> owner_type| owner_id | english| italian | german|

thats all nice and well but my problem basically is how to put the data in the content table(with forms initially intended for the “owner” tables)

the function i mentioned in the link is the function that deals with that problem. the only problem is that i don’t have the “right” place to put it.

the best place i could think of is in a class that inherits ActiveRecord and that all the models inherit it.

is there a better place?

“my problem basically is how to put the data in the content table(with forms initially intended for the “owner” tables)”


with AR saves automatically to child associations

accepts_nested_attributes_for :content

and that way you have a form for the parent and it will also save the associated child on the fly.

[http://railscasts.com/episodes/196-nested-model-form-part-1](http://railscasts.com/episodes/196-nested-model-form-part-1)

[http://railscasts.com/episodes/196-nested-model-form-part-2](http://railscasts.com/episodes/196-nested-model-form-part-2)