Hey there list- I am having problems with some @params. I have a route thats setup like this: map.connect ''page/display/:storyid'', :controller => ''page'', :action => ''display'' So when I hit an url like this: http://localhost:3000/page/display/299057304776318 I get this in my development log: Processing PageController#display (for 127.0.0.1 at Wed Jun 15 15:34:09 PDT 2005) Parameters: {"action"=>"display", "controller"=>"page", "storyid"=>"299057304776318"} Rendering page/display within layouts/page Rendering layouts/page (200 OK) Completed in 0.85494 (1 reqs/sec) | Rendering: 0.85179 (99%) But I try to assign the storyid that should be in the @params like this: class PageController < ApplicationController def display @test = @params[:storyid] end end and then in my display.rhtml <%= debug(@test) %> Shows up on the page empty like there is nothing in the @params [:storyid]. I am using the :storyid to do a net/http fetch of some content from another webserver and I am having major trouble getting this to work. It looks like it should be fine. You can see the :storyid is assigned the correct number in the dev log butr I can''t seem to access it or I am missing something obvious. Can anyone shed some light? Is there some other way to access the :storyid from the @params hash in my controller that I am missing? Thanks- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
Ezra Zygmuntowicz said the following on 2005-06-15 18:41:> But I try to assign the storyid that should be in the @params like this: > > class PageController < ApplicationController > def display > @test = @params[:storyid] > end > endMight want to try @params[''storyid''] ? There seems to be confusion as to where symbols vs strings should be used. I was bitten by that myself several times. Hope that helps, François
On 6/16/05, François Beausoleil <fbeausoleil-IQIa899fVSs@public.gmane.org> wrote:> > Ezra Zygmuntowicz said the following on 2005-06-15 18:41: > > But I try to assign the storyid that should be in the @params like this: > > > > class PageController < ApplicationController > > def display > > @test = @params[:storyid] > > end > > end > > Might want to try @params[''storyid''] ? > > There seems to be confusion as to where symbols vs strings should be > used. I was bitten by that myself several times.There should be no biting, since with the @params hash (which is actually a HashWithIndifferentAccess) evaluates symbols and strings to the same key, if I''m not mistaken. Likewise, since params is attr''d, you can drop the @, too.
I''m still trying to wrap my head around symbols versus strings. Is there any documentation as to which should be used and where? And how does it work under the hood? - Ben On Jun 16, 2005, at 2:42 PM, Michael Campbell wrote:> On 6/16/05, François Beausoleil <fbeausoleil-IQIa899fVSs@public.gmane.org> wrote: >> >> Ezra Zygmuntowicz said the following on 2005-06-15 18:41: >>> But I try to assign the storyid that should be in the @params like >>> this: >>> >>> class PageController < ApplicationController >>> def display >>> @test = @params[:storyid] >>> end >>> end >> >> Might want to try @params[''storyid''] ? >> >> There seems to be confusion as to where symbols vs strings should be >> used. I was bitten by that myself several times. > > > There should be no biting, since with the @params hash (which is > actually a HashWithIndifferentAccess) evaluates symbols and strings to > the same key, if I''m not mistaken. > > Likewise, since params is attr''d, you can drop the @, too. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi, Look in the archives for the "Symbols Help" thread. There the concepts of the symbols are explained. Flurin Ben Jackson wrote:> I''m still trying to wrap my head around symbols versus strings. Is > there any documentation as to which should be used and where? And how > does it work under the hood? > > - Ben > > On Jun 16, 2005, at 2:42 PM, Michael Campbell wrote: > >> On 6/16/05, François Beausoleil <fbeausoleil-IQIa899fVSs@public.gmane.org> wrote: >> >>> >>> Ezra Zygmuntowicz said the following on 2005-06-15 18:41: >>> >>>> But I try to assign the storyid that should be in the @params like >>>> this: >>>> >>>> class PageController < ApplicationController >>>> def display >>>> @test = @params[:storyid] >>>> end >>>> end >>> >>> >>> Might want to try @params[''storyid''] ? >>> >>> There seems to be confusion as to where symbols vs strings should be >>> used. I was bitten by that myself several times. >> >> >> >> There should be no biting, since with the @params hash (which is >> actually a HashWithIndifferentAccess) evaluates symbols and strings to >> the same key, if I''m not mistaken. >> >> Likewise, since params is attr''d, you can drop the @, too. >> _______________________________________________ >> 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
On 16-jun-2005, at 0:41, Ezra Zygmuntowicz wrote:> > But I try to assign the storyid that should be in the @params like > this: > > class PageController < ApplicationController > def display > @test = @params[:storyid] > end > end > > and then in my display.rhtml > <%= debug(@test) %> >It depends. Check if it indeed IS in the params first. Second, mind the following - Rails uses the path way (/app/controller/show/4) when you use :id for your parameter name and a query (/app/controller/show?item=5&foo=8) if you use other parameters. Most likely @params[:storyid] will never get set unless you just POSTed to the page with this parameter or sent a query that contains ? blabla&storyid=4. The last component of the path (/show/4) will always be @params[:id] on the controller side. -- Julian "Julik" Tarkhanov