# Problem on server and not on local machine?

**URL:** <https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396>\
**Category:** Rails\
**Created:** [June 3, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396 "2008-06-03T15:43:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/1 "2008-06-03T15:43:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/2 "2008-06-03T15:44:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 4:21pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/3 "2008-06-03T16:21:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/4 "2008-06-03T16:26:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/5 "2008-06-03T16:30:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/problem-on-server-and-not-on-local-machine/139396/6 "2008-06-03T16:32:17Z")

</div>

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)
