# Flex and Rails - NoMethodError

**URL:** <https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179>\
**Category:** Rails\
**Created:** [March 18, 2009, 1:29am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179 "2009-03-18T01:29:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 1:29am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/1 "2009-03-18T01:29:54Z")

</div>

Hi all!!

Recently , i tryed to integrate flex and rail, and it was a nice work,  
really fast and flexible, until a curious bug

On my local development machine, i try to destroy an item trough an id,  
and all goes well.  
i set up on the production machine and pop-up this error:

NoMethodError (undefined method `[]’ for nil:NilClass)

here’s the code of the mxml in question:

\<mx:HTTPService contentType=“application/xml” id=“destroy\_question”  
url=“[http://localhost:3000/admin/questions/destroy\_question\_xml](http://localhost:3000/admin/questions/destroy_question_xml)”  
useProxy=“false” method=“POST” result=“object\_destroyed()”  
fault=“object\_not\_destroyed()” \>  
\<mx:request xmlns=“”\>  
  
{qdg.selectedItem.id}  
  
\</mx:request\>  
\</mx:HTTPService\>

and here’s the controller:

def destroy\_question\_xml  
if params[:question][:id][:value]  
@question = Question.find(params[:question][:id][:value])  
@question.destroy  
@question.save  
end  
end

The curious thing is that actually, on production machine, it send  
correctly the values(“question”=\>{“id”=\>{“type”=\>“integer”,  
“value”=\>“96”}}) , but still pop up the error NoMethodError (undefined  
method `[]’ for nil:NilClass).

Someone has some thougt on this?

thanks a lot for reading

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 3:35am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/2 "2009-03-18T03:35:23Z")

</div>

On Tue, Mar 17, 2009 at 5:29 PM, Enzo R. \<  
removed\_email\_address@domain.invalid\> wrote:

> ```
> <id>{qdg.selectedItem.id}</id>
> @question.save
> 
> ```
> 
> thanks a lot for reading

Hi, the last two lines seem suspect because you’re trying to delete and  
save  
something. For example,

def destroy\_question\_xml  
if params[:question][:id][:value]  
@question = Question.find(params[:question][:id][:value])  
@question.destroy  
@question.save  
end  
end

Thus, I would recommend checking your logic.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 7:20am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/3 "2009-03-18T07:20:45Z")

</div>

Conrad T. wrote:

> On Tue, Mar 17, 2009 at 5:29 PM, Enzo R. \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > ```
> > <id>{qdg.selectedItem.id}</id>
> > @question.save
> > 
> > ```
> > 
> > thanks a lot for reading
> 
> Hi, the last two lines seem suspect because you’re trying to delete and  
> save  
> something. For example,
> 
> def destroy\_question\_xml  
> if params[:question][:id][:value]  
> @question = Question.find(params[:question][:id][:value])  
> @question.destroy  
> @question.save  
> end  
> end
> 
> Thus, I would recommend checking your logic.
> 
> Good luck,
> 
> -Conrad

yeah, that was a problem, but not the resolution.

i got many classes with this kind of class(of course, without the logic  
error) , and all of them works in local, don’t works on the production  
server.

anyway, thanks a lot for the reply!

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 8:17am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/4 "2009-03-18T08:17:10Z")

</div>

where exactly is the error?  
which expression is nil?

- params[:question]
- params[:question][:id]
- params[:question][:id][:value]

did you debug it?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 11:55am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/5 "2009-03-18T11:55:16Z")

</div>

Little update:

in local i use mongrel, in production phusion passenger.

can it be a problem?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 8:24am UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/6 "2009-03-18T08:24:02Z")

</div>

MaD wrote:

> where exactly is the error?  
> which expression is nil?
> 
> - params[:question]
> - params[:question][:id]
> - params[:question][:id][:value]
> 
> did you debug it?

theorically none of them , because the system passes correctly the  
values

( (“question”=\>{“id”=\>{“type”=\>“integer”,“value”=\>“96”}}) .

anyway i’m gonna debug and i’ll say more after

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 2:36pm UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/7 "2009-03-18T14:36:58Z")

</div>

Enzo R. wrote:

> Little update:
> 
> in local i use mongrel, in production phusion passenger.
> 
> can it be a problem?

problem understood!!

the server calls two times the method, because the first is halted by  
ssl\_required

Filter chain halted as [:ssl\_required] rendered\_or\_redirected.

someone know what this means?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 5:02pm UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/8 "2009-03-18T17:02:40Z")

</div>

i don’t know about your system, but maybe you try to do something over  
ssl and you don’t have it configured for your webserver?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [March 18, 2009, 10:25pm UTC](https://www.ruby-forum.com/t/flex-and-rails-nomethoderror/163179/9 "2009-03-18T22:25:59Z")

</div>

It means you have a filter called require\_ssl in your application.  
This kind of filter will usuallly either redirect or stop the current  
request if it is not made over ssl (e.g [https://example.com](https://example.com)) find the  
one in your app to see more. Either make the web request over ssl, or  
skip the filter if you don’t need to use ssl. I’d recommend to use ssl  
if this is a request that is being authenticated in some way.

Cheers,  
Jeremy

On Mar 19, 2:36 am, Enzo R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
