Forum: Ruby on Rails Ajax Checkbox using Rails

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.
6442cbabe45924d5babe9c971f09ba18?d=identicon&s=25 Ronen Levi (Guest)
on 2006-05-13 12:59
Hi,

I'm trying to have a checkbox, that when clickes sends an update to the
server and in turn modify the UI with feedback on the success of the
operation.

The main difficulty I'm encountering is that I can't pass the checkbox
value if I use the standard PrototypeHelpers.

I'm using remote_function to build the function call, but it doesn't
allow me to pass the "this.checked" from the combo to the server. As far
as I understand, the url should be written in the javascript as
"/item/5/"+this.checked, but since the url is build only of options I
can't generate this.

1. How can this be done?
2. Why isn't there checkbox_remote just like there is link_to_remote. I
would expect this also for all controls (radio buttons, edit boxes,
etc.) so maybe it is hiding there somewhere?
3. Any workaround using other methods or assistance how write my own
checkbox_remote without duplicating too much existing rails code? (as I
need to modify also the url_for to get this solved). I'd prefer to to
simply generate the whols javascript myself - I'd rather use ruby
methods for everything.

Thanks,
  Ronen
Fb23bc8cd4030c526b0689276b34c8bd?d=identicon&s=25 Bryan Duxbury (bryanduxbury)
on 2006-05-13 15:09
I think what you want to use is a field observer.

http://api.rubyonrails.com/classes/ActionView/Help...

It's really easy, and has the same syntax as link_to_remote.
6442cbabe45924d5babe9c971f09ba18?d=identicon&s=25 Ronen Levi (Guest)
on 2006-05-13 15:45
Bryan Duxbury wrote:
> I think what you want to use is a field observer.
>
> http://api.rubyonrails.com/classes/ActionView/Help...
>
> It's really easy, and has the same syntax as link_to_remote.

Not exactly since I want to have immediate response after the checkbox
is pressed. Not one that is delayed.

  Ronen
783cb603fd5be82e83ee3b68ed9e44c4?d=identicon&s=25 Adam Holt (omgitsads)
on 2006-05-13 17:41
Ronen Levi wrote:
> Bryan Duxbury wrote:
>> I think what you want to use is a field observer.
>>
>> http://api.rubyonrails.com/classes/ActionView/Help...
>>
>> It's really easy, and has the same syntax as link_to_remote.
>
> Not exactly since I want to have immediate response after the checkbox
> is pressed. Not one that is delayed.
>
>   Ronen

correct me if im wrong here like, but wouldnt you just set the frequency
to 0, hence making it event based and doing what you want when the
checkbox is clicked?

like i said correct me if im wrong, but it seems pretty self-explanitory
in the docs
6442cbabe45924d5babe9c971f09ba18?d=identicon&s=25 Ronen Levi (Guest)
on 2006-05-13 17:45
Adam Holt wrote:
>
> correct me if im wrong here like, but wouldnt you just set the frequency
> to 0, hence making it event based and doing what you want when the
> checkbox is clicked?
>
> like i said correct me if im wrong, but it seems pretty self-explanitory
> in the docs

Oops, didn't notice the statement that 0 will take a different approach.
Thanks - I'll try that.
783cb603fd5be82e83ee3b68ed9e44c4?d=identicon&s=25 Adam Holt (omgitsads)
on 2006-05-13 17:47
Ronen Levi wrote:
> Adam Holt wrote:
>>
>> correct me if im wrong here like, but wouldnt you just set the frequency
>> to 0, hence making it event based and doing what you want when the
>> checkbox is clicked?
>>
>> like i said correct me if im wrong, but it seems pretty self-explanitory
>> in the docs
>
> Oops, didn't notice the statement that 0 will take a different approach.
> Thanks - I'll try that.

no problem
This topic is locked and can not be replied to.