Problem on server and not on local machine?

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) %>

<%= @calendar.name %>

By week in <%= @calendar.name %>:

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!

Sorry left out the index:

Streams:

    <% for calendar in @stream_cals %> <% unless (calendar.hidden? && !calendar.admin_by?(current_user)) || calendar.name == 'Personal'%>
  • <%= link_to(calendar.name, :action => 'events_listing', :name => Calendar.find(calendar.id).name) %> <% end %> <% end %>

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

Frederick C. 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?

Thanks for your help!

On 3 Jun 2008, at 15:26, Amanda … wrote:

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)