Forum: Ruby on Rails Module Issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 doug (Guest)
on 2008-12-28 20:41
(Received via mailing list)
If I have a module that looks like this:

module Mymod
  require 'cgi'
  params=CGI.new
end

and I call a particular webpage like this:

http://www.mydomain.com/test1.html?test=value

and the particular web page has code in it that looks like this:

<% require mymod %>
<p><%= Mymod::params['test'] %></p>

why does this bomb instead of displaying the word 'test'?

If I move the contents of the module to the actual page, I can get it
to work just fine (of course, under that condition I omit the
'Mymod::').

How can I make this work?

Thanks for any input.

            ... doug
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-28 21:16
(Received via mailing list)
On Dec 28, 7:41 pm, doug <ddjol...@gmail.com> wrote:
> If I have a module that looks like this:
>
> module Mymod
>   require 'cgi'
>   params=CGI.new
> end
>
This doesn't make a params mehod on mymodule. It just creates a local
variable.
Not sure why you're fiddling around with CGI though.

Fred
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 doug (Guest)
on 2008-12-29 00:40
(Received via mailing list)
> This doesn't make a params mehod on mymodule. It just creates a local
> variable.

Thanks.

> Not sure why you're fiddling around with CGI though.

It's a bit of a because-it's-there type thing.  I'm just playing
around with some more basic Ruby code to see what I can and can't do.
I'm still at a loss as to how I would pass the params from the module
to the code that is requiring it.

Thanks again for the input.

          ... doug
This topic is locked and can not be replied to.