# Params hash inside \<script\> tag

**URL:** <https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377>\
**Category:** Rails\
**Created:** [July 7, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377 "2008-07-07T13:28:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/1 "2008-07-07T13:28:12Z")

</div>

Hi i need my params to use inside a tag in the same .rhtml  
file. how do i access this. Anyone please…?

Thanks  
-Sadeesh.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/2 "2008-07-07T14:01:38Z")

</div>

Don’t know, what exactly you want to do…  
Have the params hash transformed to javascript variables?

def variables\_for\_javascript(variables)  
variables.map {|k, v| “var #{k}#{’ = ’ if v}#{v};”}.sort.join("\n")  
end

something like this would do the trick in a helper  
could be easily adjusted to generate a js hash or whatever

But you question isn’t detailed enough to give you any real help

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/3 "2008-07-07T14:25:05Z")

</div>

Hi Thorsten,  
In my app, when user does a particular action, I want to show a  
greybox where the previous form element input values are needed. Here  
greybox is opened inside a script tag with specifying a url, in that  
url i need to pass the parameters that i got in this action. This is  
my real problem. I hope explained clear.

Your previous example too a controller method. Then, how do i access  
it from inside a script tag.

Looking for your valuable reply.  
Thanks,  
-Sadeesh kumar.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/4 "2008-07-07T14:38:01Z")

</div>

If you just need thee content of a param, use \<%= %\>

for example:  
\<%= params[:user][:name] %\>

you can use this wherever you want inside rhtml, it  
doesn’t matter if the area is html or script.

if you would want to use my helper, you would put  
the method in application\_helper.rb or in the helper belonging  
to the controller and just call it like

\<%= variables\_for\_javascript(params[:user]) %\>

this would generate a list of vars from the users fields in the hash.  
eg:  
var name = somename  
note, that it’s not generating parentheses around strings, I’ve  
written it for a special purpose, but it could be adjusted easy  
enough.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 3:09pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/5 "2008-07-07T15:09:45Z")

</div>

Hi,  
Really your answer cheers. I solved my problem. Thanks, for your  
quick and valuable reply. I queried another problem  
in  
[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/417bce6056e8f19a](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/417bce6056e8f19a).  
But I got no reply. Do you have any idea? Please…

Thanks,  
-Sadeesh kumar.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 8, 2008, 5:57am UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/6 "2008-07-08T05:57:13Z")

</div>

Thorsten,  
Thanks for your kind reply and big suggestions. I will follow  
your ideas hereafter.

Thanks again,  
-Sadeesh kumar.

---

<div class="post-metadata">

**Author:** ![sadeesh\_kumar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sadeesh\_kumar](https://www.ruby-forum.com/u/sadeesh_kumar)\
**Post date:** [July 7, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/params-hash-inside-script-tag/142377/7 "2008-07-07T15:25:36Z")

</div>

I queried another problem

> inhttp://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/…  
> But I got no reply. Do you have any idea? Please…

I’ve seen your post, but sorry no idea.  
I’ve never used this plugin and so no experience with it.  
And this kind of trouble, errors appearing sometimes can be very hard  
to debug.  
You would have to track down the exact circumstances, when it happens.  
Often it’s just an object that’s nil, when it shouldn’t be and then of  
course would not  
have this find\_by\_key function.  
First thing would be to know, if the error happens in one and the same  
controller/action  
all the time or in several places.  
Most likely you only use this in one controller anyway.  
Then you can post your code and the stack trace you get from the  
error. This may enable  
people to help you better, sometimes experienced programmers can tell  
you the source of  
trouble from the stack trace without knowing too much of the rest.

It’s always difficult to find a good way to post questions in a forum  
like this.  
Too short and you miss information.  
Too long and nobody finds the time to read it.  
If you don’t get answers, try to supply more information,  
but at the same time try to keep it “compact”
