Accessing link_to_remote in controller with .find(params[])

0 views
Skip to first unread message

blueHandTalking

unread,
Nov 23, 2009, 12:53:21 PM11/23/09
to Hobo Users
The following:

<% @project_details.each do |project_detail| %>

<%= link_to_remote ( :with => "'architect='+ #
{project_detail.architect}") %>
<% end %>
generates

{asynchronous:true, evalScripts:true, parameters:'architect=' + 'Jack
London ' + ...more stuff

Is the above then available in params array in the controller, and if
so how?

Right now I am trying:

@photos = Photo.find_by_architect(params[:architect:])

which does not work.

Thanks,

Jet

kevinpfromnm

unread,
Nov 23, 2009, 3:03:17 PM11/23/09
to Hobo Users
I'm not sure but I would guess 'architect=' is not the same as
'architect'= ... my javascript is a bit rusty.

blueHandTalking

unread,
Nov 23, 2009, 6:47:16 PM11/23/09
to Hobo Users
Kevin,

Thanks for the guestimate. My question was off topic,
but I thought I'd give it a shot. My javascript is almost non-
existant,
so I am struggling with Prototype.

Here is the example from the Rails docs:

:with => "'name=' + $('name').value"

I am getting same result (I believe) with

:with => "'architect = ' + #{project_detail.architect}"

...as the output looks fine in Firebug.

Where I am having trouble is in the controller.
How do I pick this up there?

I was trying

params[:architect]

or with another construct ( project_details['architect] =
project_details['architect']) in the
javascript reply I tried

params([:project_details][:architect]

in the controller, but this did not seem to work either.


Lacking the knowledge to pick up the vars out of javascript reply in
the controller.

Thanks again,

Jet

Matt Jones

unread,
Nov 23, 2009, 7:07:35 PM11/23/09
to hobo...@googlegroups.com

On Nov 23, 2009, at 6:47 PM, blueHandTalking wrote:

> Kevin,
>
> Thanks for the guestimate. My question was off topic,
> but I thought I'd give it a shot. My javascript is almost non-
> existant,
> so I am struggling with Prototype.
>
> Here is the example from the Rails docs:
>
> :with => "'name=' + $('name').value"
>
> I am getting same result (I believe) with
>
> :with => "'architect = ' + #{project_detail.architect}"
>
> ...as the output looks fine in Firebug.
>
> Where I am having trouble is in the controller.
> How do I pick this up there?
>

Couple things:

- skip the spaces. The :with option is pretty much whacked into the
query string as-is. For your setup, you'll probably need something
more like (note the single quotes:

:with => "'architect=#{escape_once(project_detail.architect)}'"

(not 100% sure if escape_once is in 2.3.x; you essentially need to
escape the space in project_detail.architect)

- the output from script/server (or the logs) is the best place to
look for params that have wandered off. What does it show when you
execute this request?

Hope this helps!

--Matt Jones

blueHandTalking

unread,
Nov 24, 2009, 4:52:42 PM11/24/09
to Hobo Users
Matt,

Yes, Thank you!

I removed 'escape_once' and replaced with:

:with => "'architect='+encodeURIComponent('#
{project_detail.architect}')"

This was necessary to deal with bad ampersands.

Cheers,

Jet
Reply all
Reply to author
Forward
0 new messages