Forum: Ruby on Rails add a column "on the fly"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Held O. (Guest)
on 2008-12-08 20:33
Hi people,

Does anybody know if it is possible to create columns on the fly..
so wihout a migration.

I would like to do this so that my customers can create multiple
languages whitout me generating that language for them.

ohw an second question: could I then check if a particularly column
exists ? in a table of course :P

thanxs!
Frederick C. (Guest)
on 2008-12-08 23:17
(Received via mailing list)
On 8 Dec 2008, at 18:33, jeljer te Wies wrote:

> exists ? in a table of course :P
>
Well you can of course execute arbitrary sql
(ActiveRecord::Base.connection.execute), which could add a column (you
will run into the slight issue that you will need to get all of your
mongrels/mod_rails instances etc... to call
SomeTable.reset_column_information). This sounds like a horrifically
bad idea though

Fred
Held O. (Guest)
on 2008-12-08 23:28
:( If you put it like that yes !..
Such a shame ! Beceaus it would have been verry cool
To add languages on the fly as a customer :(

Ok wel then I will have to do something with my database design
So that I would be possible.... But it won't be pritty either :(

Thanxs allot though for the reply !
I really apreciate it

Jeljer


Frederick C. wrote:
> On 8 Dec 2008, at 18:33, jeljer te Wies wrote:
>
>> exists ? in a table of course :P
>>
> Well you can of course execute arbitrary sql
> (ActiveRecord::Base.connection.execute), which could add a column (you
> will run into the slight issue that you will need to get all of your
> mongrels/mod_rails instances etc... to call
> SomeTable.reset_column_information). This sounds like a horrifically
> bad idea though
>
> Fred
Frederick C. (Guest)
on 2008-12-08 23:37
(Received via mailing list)
On 8 Dec 2008, at 21:28, jeljer te Wies wrote:

>
>
> :( If you put it like that yes !..
> Such a shame ! Beceaus it would have been verry cool
> To add languages on the fly as a customer :(
>

I've absolutely no idea what you're doing or trying to do, but I doubt
that adding columns on the fly is the only way to accomplish what you
want.

Fred
Paweł K (Guest)
on 2008-12-09 16:47
(Received via mailing list)
Why can't you make an additional model "language" and another model of
"message", then you only need:

language.rb: has_many => :messages
message.rb: belongs_to => :language

Then you might have infinite number of languages with infinite number
of messages ;)))

Good luck! :)

On Dec 8, 10:36 pm, Frederick C. <removed_email_address@domain.invalid>
Held O. (Guest)
on 2008-12-09 16:52
Yes thanxs !.. I have thought of the same solution.

I now have the following.. :

Languages:
      -id
      -name

menus
     -id
     -title
     -languages id

This is a much better solution !! .. I really don't know why haven't
thought of it
sooner.

Thanxs for al the replays guys!.

gr jeljer


Paweł K wrote:
> Why can't you make an additional model "language" and another model of
> "message", then you only need:
>
> language.rb: has_many => :messages
> message.rb: belongs_to => :language
>
> Then you might have infinite number of languages with infinite number
> of messages ;)))
>
> Good luck! :)
>
> On Dec 8, 10:36 pm, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.