How to change db values without a form

HI all,

I have an index page in my site and each item displayed from the model
has a link (that looks like a button)… I want that link to simply
clear a field (or set it to some value) in the underlying model for
that entry… The page does not have a form on it and i’d like to
avoid that if possible…

seems i should be able to select the link and have it process an
update on the item behind the scenes and then re-display the page (or
if i get fancier later - use ajax to red-display the item?)…

I hope this makes sense… i’m obviously new to web dev AND rails…

thanks

On 27 October 2011 21:32, Max [email protected] wrote:

if i get fancier later - use ajax to red-display the item?)…

I hope this makes sense… i’m obviously new to web dev AND rails…

A simple way, avoiding AJAX and so on until you have more experience,
is to have an empty form with just the submit button. To the user it
will just look like a button but Rails will do all the clever stuff
for you. You just need to provide the action and (if appropriate)
re-display the same view.

Colin

On Thu, Oct 27, 2011 at 16:32, Max [email protected] wrote:

seems i should be able to select the link and have it process an
update on the item behind the scenes and then re-display the page (or
if i get fancier later - use ajax to red-display the item?)…

You’re right, you don’t need a form to process anything. What springs
to my mind offhand is to have the link send an AJAX request to the
server, to clear/set the field in question, and when you get back the
confirmation, show it on the screen as cleared/set. (Most likely by
getting back the data for the new value of the whole item, and
updating the item’s representation on the view.)

-Dave


LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern
languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote
work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com
(excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble!
(Aronson)

On Thu, Oct 27, 2011 at 1:32 PM, Max [email protected] wrote:

I have an index page in my site and each item displayed from the model
has a link (that looks like a button)… I want that link to simply
clear a field (or set it to some value) in the underlying model for
that entry…

Uh, realizing that every time a spider comes along to index your site,
every one of those links will be activated? (unless the page in question
is password protected)

The page does not have a form on it and i’d like to avoid that if possible…

Google ‘http idempotent request’ to understand why you should use a
POST rather than GET for actions that change data.

HTH,

Hassan S. ------------------------ [email protected]

twitter: @hassan