[Facebooker-talk] facebook_form_for + a little ajax?
Zhao Lu
zhao.lu.us at gmail.com
Thu Sep 11 15:06:13 EDT 2008
Thanks for your answer Mike. I was calling select_tag by itself
without the wrapping,
which is indeed what I need to do. Now I have passed that having some
problem with
getting hold of a ruby class I defined from javascript. I can't seem
to find an example
online. Here's my code:
<p id="resource" > </p>
<% facebook_form_for :facebook_gift, FacebookGift.new, :url =>
facebook_gifts_path do |f| %>
<%=
@gift_catalog = GiftCatalog.find(:all, :order => "name").map { |gc|
[gc.resource.file_name, gc.id]}
f.text select_tag(:gift_catalog_id,
options_for_select(@gift_catalog), :onchange =>
"update_gift_display(this.getValue(), 'resource');")
%>
//more code here
<%end%>
I have some javascript on the same page:
<script>
function update_gift_display(gc_id, update_widget) {
uri = GiftCatalog.find(gc_id).resource.resource_uri
$(update_widget).setTextValue(uri)
}
</script>
So what I'm trying to achieve is for user to select a gift_catalog_id,
then I will get the url to
the actual gift (which is linked to gift_catalog). But GiftCatalog is
not available in the javascript function.
I feel that I'm not on the right track for this. Any suggestion would
be greatly appreciated.
Zhao
On Thu, Sep 11, 2008 at 5:30 AM, Mike Mangino
<mmangino at elevatedrails.com> wrote:
> Are you calling form.select_tag? That won't work. select_tag is not a method
> on the form builder (this is true any time you use form_for in rails)
>
> You can do form.text select_tag... to wrap a normal select inside a facebook
> form.
>
> Mike
> On Sep 11, 2008, at 1:45 AM, Zhao Lu wrote:
>
>> Hello Everyone,
>>
>> I'm using a facebook_form_for which is bound to a model. In the form
>> I have a form.select which is populated with an array of the names of
>> images.
>> Whenever I change the selection I'd like to display the image on the
>> same page. I tried to change form.select to select_tag but that
>> doesn't seem to play well with facebook_form_for. I'm pretty confused
>> as to how to approach this. Any suggestion would be appreciated.
>>
>> --
>> Zhao
>> _______________________________________________
>> Facebooker-talk mailing list
>> Facebooker-talk at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/facebooker-talk
>
> --
> Mike Mangino
> http://www.elevatedrails.com
>
>
>
>
--
Zhao
More information about the Facebooker-talk
mailing list