Posted almost 10 years ago by Philip Ingram
It appears to me, that google only knows how to display Active Resource examples that use the Console to display the good stuff.
I’ve learned a lot from reading the Active Resource railscast 94 and Active Resource railscast 95 . I also read the chapter in the Rails in a Nutshell book . (Thanks to Cody Fauser, James MacAulay, Edward Ocampo-Gooding, and John Guenin, btw).
Each one of these sources used the console to show how slick this worked. Awesome, I get why they showed their work using the console too, but in the real world, we use views to get user input to an Active Resource.
The app i was creating needed a user to fill in a form and hit submit, wait, and get the response back. I wanted the model that was doing all the work to be on another server, so instantly we think of Active Resource to facilitate this workflow.
When using Active Resource and forms to input the data that will be needed, you cannot use form_for; Instead, use form_tag made to act like form_for.
That one sentence above has saved you 10000000000 years of wtf. Your welcome :-)
From the api:
form_for – Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.
After seeing in countless resources "Active Resource just works like Active Record… " etc, etc I thought that i was dealing with a “Model Object” but I may have taken that point a little too literally. If you are reading this, then so have you I’m sure.
Again, let’s make a form_tag form look and act like a form_for. To the code:
Company_Name Account Activation Form - Credit Card <h2>Choose your Company_Name Plan </h2> <p> </p> <h2>Billing Information</h2> <p> </p> <p> </p> <h2>Credit Card Information</h2> <p> <small>(Only Visa or Mastercard, sorry.)</small> </p> <p> "width: 120px" %> </p> <p> "width: 25px" %> </p> <p> true, :prefix => "model", :field_name => "card_month") %> Date.today.year, :end_year => (Date.today.year+10), :prefix => "model", :field_name => "card_year" %> </p> request.remote_ip %> <p> 'Processing Please Wait...' %></p>
:prefix => “model”, :field_name => “card_year”
Well that’s it for magic sauce i think. The rest comes down to how you validate, save data etc, in your Active Resource model.
Happy Active Resourcing.