Michael Glaesemann
2005-Jan-28 07:44 UTC
primary_key_prefix_type, support for non-integer primary keys
Hello! I''m just starting out with Rails--and Ruby itself for that matter--and have a couple of questions regarding primary_key_prefix_type and non-integer primary keys. I see in the ActiveRecord documentation [1] that by default the primary key of a table "foo" is expected to be "id", though primary_key_prefix_type this can be changed to :table_name or :table_name_with_underscore for "fooid" and "foo_id" respectively. I''m unclear where to set this or the syntax I should use. My attempt has been to add code to environment.rb things such as ActiveRecord::Base.primary_key_prefix_type :table_name_with_underscore or def ActiveRecord::Base.primary_key_prefix_type() :table_name_with_underscore end or even def ActiveRecord::Base.attributes = (primary_key_prefix_type = :table_name_with_underscore) end The first two give me syntax errors, while the third presents me with Method Not Found. I''m sure the above code is clear evidence of exactly how much I have to learn :) But I''m looking forward to it. The docs also mention that primary_key_prefix_type is a global setting. Does this mean that this attribute will affect all ActiveRecords in all apps on the installation or just the ActiveRecords for the app it''s set in? Knowing where to put this attribute setting will make it clear, I''m sure. I can currently work around this using def self.primary_key() : I also am interested in using non-integer primary keys, in particular for things such as localization script codes where I''d rather use "en_US" or "ja_JP" for the primary key than tack on another column. The only mention I''ve found of non-integer primary keys is in the ActiveRecord changelog entry for 0.8.3. I''d be grateful if someone could point me someplace where I could learn more about this and how to use it. I''ve googled quite extensively, and I know there''s a lot I still need to learn. Any hints or pointers to where I might find more information and examples are greatly appreciated. Thanks! Michael Glaesemann grzm myrealbox com [1] <http://ar.rubyonrails.org/classes/ActiveRecord/Base.html#attribute- list>
Greetings All! Now that I seem to have gotten my head around whats going on with rails (at least enough to consistently create the default app, LoL) , I want to play around with some of the the other gems to enhance my web app, things like crypt-based auth and the redcloth package, for instance. So, it would be usefull for me to be able to read the documentation for these things; I cant seem to find out how for the life of me. I''d like to be able to examine doc for uninstalled or not yet installed packages, and to read doc for installed packages as well. This is probably something so simple I''m missing the obvious; if someone could drop-kick me in the right direction I''d really appreciate it :) Cheers, Twitch
$ gem_server point ye ole browser at http://localhost:8808/ consider thy self kicked. :-) On Fri, 28 Jan 2005 07:53:22 -0600, James Stallings II <twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote:> Greetings All! > > Now that I seem to have gotten my head around whats going on with rails > (at least enough to consistently create the default app, LoL) , I want > to play around with some of the the other gems to enhance my web app, > things like crypt-based auth and the redcloth package, for instance. > > So, it would be usefull for me to be able to read the documentation for > these things; I cant seem to find out how for the life of me. I''d like > to be able to examine doc for uninstalled or not yet installed packages, > and to read doc for installed packages as well. > > This is probably something so simple I''m missing the obvious; if someone > could drop-kick me in the right direction I''d really appreciate it :) > > Cheers, > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- This is my sig. Isn''t it cool...
Hello, try to run gem_server, and then navigate to localhost:8808. I''m using it pretty much :-) -- Pepe On 28.1.2005, at 14:53, James Stallings II wrote:> Greetings All! > > Now that I seem to have gotten my head around whats going on with > rails (at least enough to consistently create the default app, LoL) , > I want to play around with some of the the other gems to enhance my > web app, things like crypt-based auth and the redcloth package, for > instance. > > So, it would be usefull for me to be able to read the documentation > for these things; I cant seem to find out how for the life of me. I''d > like to be able to examine doc for uninstalled or not yet installed > packages, and to read doc for installed packages as well. > > This is probably something so simple I''m missing the obvious; if > someone could drop-kick me in the right direction I''d really > appreciate it :) > > Cheers, > Twitch > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Dale K. Hawkins wrote:>$ gem_server > >point ye ole browser at http://localhost:8808/ > >consider thy self kicked. :-) > > >On Fri, 28 Jan 2005 07:53:22 -0600, James Stallings II ><twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote: > > >>Greetings All! >> >>Now that I seem to have gotten my head around whats going on with rails >>(at least enough to consistently create the default app, LoL) , I want >>to play around with some of the the other gems to enhance my web app, >>things like crypt-based auth and the redcloth package, for instance. >> >>So, it would be usefull for me to be able to read the documentation for >>these things; I cant seem to find out how for the life of me. I''d like >>to be able to examine doc for uninstalled or not yet installed packages, >>and to read doc for installed packages as well. >> >>This is probably something so simple I''m missing the obvious; if someone >>could drop-kick me in the right direction I''d really appreciate it :) >> >>Cheers, >>Twitch >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >Beautiful, Ladies! Thank You So Much! :P Cheers, Twitch
Is there a way to use a different layout for certain actions inside a controller? -- Ben Sinclair ben-bgLzOLc97kcYkl5+HhvCNA@public.gmane.org
There is an example on the wiki of adding Redcloth/Textile support to a rails app. http://manuals.rubyonrails.com/read/chapter/48 (install it) http://manuals.rubyonrails.com/read/chapter/51#page148 (scroll down slighty to see textilize_without_paragraph in the view) On Fri, 28 Jan 2005 08:36:36 -0600, James G. Stallings II <twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote:> Dale K. Hawkins wrote: > > >$ gem_server > > > >point ye ole browser at http://localhost:8808/ > > > >consider thy self kicked. :-) > > > > > >On Fri, 28 Jan 2005 07:53:22 -0600, James Stallings II > ><twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote: > > > > > >>Greetings All! > >> > >>Now that I seem to have gotten my head around whats going on with rails > >>(at least enough to consistently create the default app, LoL) , I want > >>to play around with some of the the other gems to enhance my web app, > >>things like crypt-based auth and the redcloth package, for instance. > >> > >>So, it would be usefull for me to be able to read the documentation for > >>these things; I cant seem to find out how for the life of me. I''d like > >>to be able to examine doc for uninstalled or not yet installed packages, > >>and to read doc for installed packages as well. > >> > >>This is probably something so simple I''m missing the obvious; if someone > >>could drop-kick me in the right direction I''d really appreciate it :) > >> > >>Cheers, > >>Twitch > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > > > > > > > > > Beautiful, Ladies! > > Thank You So Much! > > :P > > Cheers, > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ben, By default the layout is defined by the [action_name].rhtml file in app/views/[controllername]/ (unless you''re using scaffolding), so it is exactly what you make it be. Thus, by default the actions are not sharing any layouts. If you then *want* the actions to share a layout, you might want to take a look at rails layouts: http://rails.rubyonrails.com/classes/ActionController/Layout/ ClassMethods.html //jarkko On 28.1.2005, at 16:45, Ben Sinclair wrote:> Is there a way to use a different layout for certain actions inside a > controller? > > -- > Ben Sinclair > ben-bgLzOLc97kcYkl5+HhvCNA@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Steve Longdo wrote:>There is an example on the wiki of adding Redcloth/Textile support to >a rails app. > >http://manuals.rubyonrails.com/read/chapter/48 (install it) >http://manuals.rubyonrails.com/read/chapter/51#page148 (scroll down >slighty to see textilize_without_paragraph in the view) > >Dude you RULE I was just busting my hump looking for this :D Cheers, Twitch
James G. Stallings II wrote:> Steve Longdo wrote: > >> There is an example on the wiki of adding Redcloth/Textile support to >> a rails app. >> >> http://manuals.rubyonrails.com/read/chapter/48 (install it) >> http://manuals.rubyonrails.com/read/chapter/51#page148 (scroll down >> slighty to see textilize_without_paragraph in the view) >> >> > Dude you RULE I was just busting my hump looking for this :D > > Cheers, > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsArgh except it doesn''t show any examples of bluecloth useage, just how to install it with gem :( Anybody wanna throw me a bone? Cheers! Twitch
Before the shouts start coming in I found more stuff at that link :) Thanks! Twitch
James G. Stallings II wrote:> Before the shouts start coming in I found more stuff at that link :) > > Thanks! > > Twitch > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsGot it. Specific RedCloth usage example in Hieraki code at http://manuals.rubyonrails.com/read/chapter/51#page148 :D Twitch
James G. Stallings II wrote:> James G. Stallings II wrote: > >> Before the shouts start coming in I found more stuff at that link :) >> >> Thanks! >> >> Twitch >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > Got it. > > Specific RedCloth usage example in Hieraki code at > http://manuals.rubyonrails.com/read/chapter/51#page148 > > :D > > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsExcellent its working guys. I''ll shut up and quit posting for a while now :) Thanks for the excellent tip Steve L. Cheers, Twitch
I''m not sure if it''s just my understanding of layouts or what, but I was a bit confused by the following:> By default the layout is defined by the [action_name].rhtml file in > app/views/[controllername]/ (unless you''re using scaffolding), so it is > exactly what you make it be.It is my understanding that *views* are defined by the action name by default, and that there is no layout by default. In other words, a layout is a special kind of view that is can be shared across several actions or views if explicitly made to do so. For example: class MySpecialController < ApplicationController layout "default" ... def list ... end end The ''list'' action will by default render the /app/views/my_special/list.rhtml view, but because there is a "layout" directive in the class, the layout in /app/views/layouts/default.rhtml will be called first, and the contents of list.rhtml will be placed wherever the <%= @content_for_layout %> variable is found. I hope this helps! Duane Johnson (canadaduane)
Actually there is a layout by default: app/layout/[controllername].rhtml (if it exists) Duane Johnson wrote:>I''m not sure if it''s just my understanding of layouts or what, but I >was a bit confused by the following: > > > >>By default the layout is defined by the [action_name].rhtml file in >>app/views/[controllername]/ (unless you''re using scaffolding), so it is >>exactly what you make it be. >> >> > >It is my understanding that *views* are defined by the action name by >default, and that there is no layout by default. In other words, a >layout is a special kind of view that is can be shared across several >actions or views if explicitly made to do so. > >For example: > >class MySpecialController < ApplicationController > layout "default" > ... > def list > ... > end >end > >The ''list'' action will by default render the >/app/views/my_special/list.rhtml view, but because there is a "layout" >directive in the class, the layout in /app/views/layouts/default.rhtml >will be called first, and the contents of list.rhtml will be placed >wherever the <%= @content_for_layout %> variable is found. > >I hope this helps! > >Duane Johnson >(canadaduane) >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
I am not sure about what you are needing but I have something like: class MyController < ApplicationController layout :select_layout (all methods go here) private def select_layout [ ''index'', ''list'', ''view'' ].include?(action_name) ? "site" : "user" end end So depending on the action being called, i can use a different layout. This works with newish Rails versions (didn''t work with my 0.9.3 but since then I am using EdgeRails ... living on the edge is good). Just my 2 cents. /B On Sat, 29 Jan 2005 15:26:03 +0100, F. Egger <f.egger.mailings-c2BlD8dJSIudKNnQ2JlF7Q@public.gmane.org> wrote:> Actually there is a layout by default: app/layout/[controllername].rhtml > (if it exists) > > Duane Johnson wrote: > > >I''m not sure if it''s just my understanding of layouts or what, but I > >was a bit confused by the following: > > > > > > > >>By default the layout is defined by the [action_name].rhtml file in > >>app/views/[controllername]/ (unless you''re using scaffolding), so it is > >>exactly what you make it be. > >> > >> > > > >It is my understanding that *views* are defined by the action name by > >default, and that there is no layout by default. In other words, a > >layout is a special kind of view that is can be shared across several > >actions or views if explicitly made to do so. > > > >For example: > > > >class MySpecialController < ApplicationController > > layout "default" > > ... > > def list > > ... > > end > >end > > > >The ''list'' action will by default render the > >/app/views/my_special/list.rhtml view, but because there is a "layout" > >directive in the class, the layout in /app/views/layouts/default.rhtml > >will be called first, and the contents of list.rhtml will be placed > >wherever the <%= @content_for_layout %> variable is found. > > > >I hope this helps! > > > >Duane Johnson > >(canadaduane) > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Bruno Mattarollo <bruno.mattarollo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On 29.1.2005, at 02:08, Duane Johnson wrote:> I''m not sure if it''s just my understanding of layouts or what, but I > was a bit confused by the following:Sorry, I answered Ben yesterday, but it seems my response cam not to the list. I wasn''t sure at first if Ben meant layout in general (as a web design term) or RoR Layouts. The latter turned out to be the case. So here''s my response from yesterday, although I think Bruno already covered this pretty well: On 28.1.2005, at 18:18, Ben Sinclair wrote:> Well, what I really meant was I want to override the layout for a > certain action in my controller.Yes, you can. class WeblogController < ActionController::Base layout "weblog_standard", :except => :rss # ... end This will use the layout for all actions except rss. See the bottom of the api docs for more options: http://rails.rubyonrails.com/classes/ActionController/Layout/ ClassMethods.html -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails