Okay so originally I had code that would allow a user to browse through all events on my site ( its a calendar site that people can submit events to) but now I''ve altered the code (by adding a global variable $calendar) to only browse through events of the specified calendar $calendar. On my local machine this code has no problems..when i upload it to our server it''s telling me $calendar.name is nil and $calendar.id is nil...but when i put my code in if stmts, to check if either is nil, it still tries to complete the code inside...so it''s telling me the values are nil but really they''re not? Could this be a problem with using the same database on my local machine and the server or something? here is my code: class BrowseController < ApplicationController def index @title = "Browse UW Events" @aud_cals = Audience.find :all @stream_cals = Stream.find :all render :layout => "application_no_side" end def events_listing @title = "Browse "+ params[:name] @date = Time.new#.beginning_of_week params[:year] = @date.year params[:month] = @date.month params[:day] = @date.day week render :action => ''week'' end events_listing view: <% $calendar = Calendar.find_by_name(params[:name]) %> week view: <% @calendar = Calendar.find($calendar.id) %> <h1><%= @calendar.name %></h1> <p class="navigation-hint">By week in <%= @calendar.name %>:</p> This code works fine on my local machine but tells me: "RuntimeError in Browse#events_listing Showing app/views/browse/week.rhtml where line #1 raised: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" I don''t see how this could possibly be nil...there is a value in the table and it works on my local machine. Im so confused by this, any help would be awesome! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry left out the index: <h2>Streams:</h2> <ul class="timeline"> <% for calendar in @stream_cals %> <% unless (calendar.hidden? && !calendar.admin_by?(current_user)) || calendar.name == ''Personal''%> <li class="vevent"><%= link_to(calendar.name, :action => ''events_listing'', :name => Calendar.find(calendar.id).name) %> <% end %> <% end %> </ul> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ll guess that in production you have more than one mongrel/fastcgi listener etc... In that case if $calendar is set by one action, on your next action the request could be served by a different mongrel where $calendar is not set (or was set by a different user). In development there is only one mongrel and one user, so it''s ok. In general global variables are a really really bad idea. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> > In general global variables are a really really bad idea. > > FredHow else would I carry the calendar info over different views? I get the information from the index and then need to use it everywhere else...thats the part that I''m stuck at. Do you have any suggestion on how i could do this? I thought about making an extra controller or something so that I can have the index on its own completely then send the calendar info over to the other controller? not sure how i would do this really. Oh and I''m a newbie to RoR..could tell me what a mongrel is? Thanks for your help! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Jun 2008, at 15:26, Amanda .. wrote:> > Frederick Cheung wrote: >> >> In general global variables are a really really bad idea. >> >> Fred > > > How else would I carry the calendar info over different views? I get > the > information from the index and then need to use it everywhere > else...thats the part that I''m stuck at. Do you have any suggestion on > how i could do this? I thought about making an extra controller or > something so that I can have the index on its own completely then send > the calendar info over to the other controller? not sure how i would > do > this really. > > Oh and I''m a newbie to RoR..could tell me what a mongrel is? >mongrel is an application server. In one common setup, mongrel is the program that actually loads up your rails code and hands incoming requests to it. If you need to carry state between actions then typically one uses the session - that''s what it''s there for. Other mechanisms include making your links include the extra parameters (eg on a search page the next link might include in it the query) or storing the state somewhere in the database (eg in the customers table) Fred
I guess I''ll have to try to figure out a way to add it to the parameters for different views. lol that''ll be fun ( I didn''t initially write the code) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---