Params hash inside <script> tag

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


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

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

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

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.
-Sadeesh kumar.

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.
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

Really your answer cheers. I solved my problem. Thanks, for your
quick and valuable reply. I queried another problem
But I got no reply. Do you have any idea? Please…

-Sadeesh kumar.

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

Thanks again,
-Sadeesh kumar.

I queried another problem

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
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”