OK, OK, I feel plenty foolish now. But I''ve tried what seemed appropriate to me, and it no workee.I hunted around in the FAQs, knowing that this had to be something simple, and no luck. What I''m trying to do is simply set up Rails to run on our Linux Apache server. I don''t have a spare DNS name available and so can''t use a VirtualHost directive; when I yanked a production DNS name for thirty seconds, the following config fragment out of the Tutorial worked just fine: <VirtualHost my_ip_number:80> ServerName My.stolen.DNS.name DocumentRoot /path/application/public/ ErrorLog /path/application/log/apache.log <Directory /path/application/public/> Options ExecCGI FollowSymLinks AddHandler cgi-script .cgi AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost> But when I tried to set up something similar using nothing but <Directory>, Alias, and ScriptAlias directives, I couldn''t see the welcome page--a bunch of 404s. ??? Thanks (again), rw
Hello! I''m a heavy php user diving headfirst into RoR. Love it so far, but I''ve got this problem I''m just not able to understand. I''ve got a model ("person") with a time field ("most_recent_year"). When I''m viewing an individual person, I can display the year portion of the time by calling <%= @person.most_recent_year.year %> in my template. It works great -- I get the year, just like I want. When I''m listing all of the people, I want to display several fields, including the year portion of most_recent_year. In my partial template ("display") that I''ve sent the collection of people to, I''ve got <%= display.most_recent_year.year %> This gives me the error "undefined method `year'' for nil:NilClass". If I leave off the .year, I get the full time displayed: "Tue Jan 01 00:00:00 Eastern Standard Time 2002" Why does it work for a person but not for people? What should I be doing (not strftime() -- that gives me exactly the same errors)? Thank you! Eric Wagoner
Ask Bjørn Hansen
2005-Aug-27 08:40 UTC
Re: Rails on Apache: VirtualHost vs Directory config
On Aug 26, 2005, at 15:49, Rick Wayne wrote:> But when I tried to set up something similar using nothing but > <Directory>, Alias, and ScriptAlias directives, I couldn''t see the > welcome page--a bunch of 404s.It''d be easier to help if you showed that "something similar". You should probably have used <Location> or Alias to map the virtual directory to the directory on disk. - ask -- http://askask.com/ - http://develooper.com/
For whatever reason, your object "display" does not contain a Person object, therefore there is no "most_recent_year" field (instead Nil). Regards, Tomas On 8/27/05, Eric Wagoner <eric-gPcogUOuSIWWkzVdRvz7FA@public.gmane.org> wrote:> Hello! > > I''m a heavy php user diving headfirst into RoR. Love it so far, but > I''ve got this problem I''m just not able to understand. > > I''ve got a model ("person") with a time field ("most_recent_year"). > > When I''m viewing an individual person, I can display the year portion > of the time by calling > > <%= @person.most_recent_year.year %> > > in my template. It works great -- I get the year, just like I want. > > When I''m listing all of the people, I want to display several fields, > including the year portion of most_recent_year. In my partial template > ("display") that I''ve sent the collection of people to, I''ve got > > <%= display.most_recent_year.year %> > > This gives me the error "undefined method `year'' for nil:NilClass". If > I leave off the .year, I get the full time displayed: "Tue Jan 01 > 00:00:00 Eastern Standard Time 2002" > > Why does it work for a person but not for people? What should I be > doing (not strftime() -- that gives me exactly the same errors)? > > Thank you! > > Eric Wagoner > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 26 Aug 2005, at 11:49 pm, Rick Wayne wrote:> OK, OK, I feel plenty foolish now. But I''ve tried what seemed > appropriate to me, and it no workee.I hunted around in the FAQs, > knowing that this had to be something simple, and no luck. > > What I''m trying to do is simply set up Rails to run on our Linux > Apache server.<snip>> But when I tried to set up something similar using nothing but > <Directory>, Alias, and ScriptAlias directives, I couldn''t see the > welcome page--a bunch of 404s.Don''t use a virtual directory; use a symlink. Rails is apparently smart enough to figure out that it''s being symlinked in, and then generates URLs correctly. Basically, dump your Rails app into a directory like /var/www/localhost/apps/myrailsapp and then make a symlink where you want it to appear in the site structure. So if you want to browse to http://www.example.com/ railstest/ and see your app, do a ln -s /var/www/localhost/apps/myrailsapp/public /var/www/ localhost/htdocs/railstest Then set up your cgi settings in a <Directory> directive in Apache like <Directory /var/www/localhost/apps/myrailsapp> ... </Directory> And obviously you need to be following symlinks in htdocs/ directory. This is pretty much lifted straight from the Book, and it''s how I''ve got a couple of Rails apps running on one of our servers. Good luck! Chris
In article <430F9C96.2060805-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org>, fewayne- rphTv4pjVZMJGwgDXS7ZQA-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> But when I tried to set up something similar using nothing but > <Directory>, Alias, and ScriptAlias directives, I couldn''t see the > welcome page--a bunch of 404s.Note that RewriteRules - and thus, quite possibly, Alias - don''t set up the hostname in a way that Rails''s .htaccess file can read; they pass the *full* pathname/URL in, instead of the "local" portion, so that where Rails expects to see "/", it might see "/srv/www/rails/public/" instead. It''s a bug/misfeature in Apache that I''ve had no luck in getting anyone''s interest in, and it makes it hard to do Rails in anything but an explicit VirtualHost. IIRC, the workaround is adding RewriteBase in the .htaccess, telling what that current directory is. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
As far as I know, you can''t call attribute methods like that on a collection. Since it''s just an array (of people objects in your case), when you try to call most_recent_year you should get something like undefined method most_recent_year for #<Array:memory_address>. I could be completely wrong, but I''ve got a feeling that display isn''t what you think it is. Set a breakpoint in your controller at the end of your method that displays the partial, and see what display really is. -- Mando On 8/27/05, Eric Wagoner <eric-gPcogUOuSIWWkzVdRvz7FA@public.gmane.org> wrote:> > Hello! > > I''m a heavy php user diving headfirst into RoR. Love it so far, but > I''ve got this problem I''m just not able to understand. > > I''ve got a model ("person") with a time field ("most_recent_year"). > > When I''m viewing an individual person, I can display the year portion > of the time by calling > > <%= @person.most_recent_year.year %> > > in my template. It works great -- I get the year, just like I want. > > When I''m listing all of the people, I want to display several fields, > including the year portion of most_recent_year. In my partial template > ("display") that I''ve sent the collection of people to, I''ve got > > <%= display.most_recent_year.year %> > > This gives me the error "undefined method `year'' for nil:NilClass". If > I leave off the .year, I get the full time displayed: "Tue Jan 01 > 00:00:00 Eastern Standard Time 2002" > > Why does it work for a person but not for people? What should I be > doing (not strftime() -- that gives me exactly the same errors)? > > Thank you! > > Eric Wagoner > _______________________________________________ > 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
Tomas wrote:> For whatever reason, your object "display" does not contain a Person > object, therefore there is no "most_recent_year" field (instead Nil).Aha! While trying to refute your assertion, I discovered that some people had null most_recent_years in the (legacy) database. Those nulls broke things for all people but didn''t give me a clear reason why. I am now catching the nulls, and everything is great. Thanks so much! -eric