You are here: Forums Ask a Rails expert Using forms in Ruby on Rails...
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 0
Sign in to rate this post
|
I am currently developing this website on ruby on rails and I got stuck. I created a form, using html (<form name>) but now I want to pass the data entered in the form to the Controller to save it to the db. How would I pass the two fields to the controller, assuming I have a database called “People”. Thanks |
Authority 12
Posting Rating 50
Sign in to rate this post
|
Hello New User, try this very goog tutorial about beginning rails. http://articles.sitepoint.com/article/learn-ruby-on-rails Axel |
Authority 0
Posting Rating 0
Sign in to rate this post
|
thanks for the link I actually already went through that tutorial and many others. Again, most tutorials explain how to pass data to the Controller if you used rails to build the form. I used plain html to build the form and would like to know how the data input in the form can be passed to the rails controller. |
Authority 12
Posting Rating 59
Sign in to rate this post
|
The data is passed with the HTTP POST, the controller receives a hash on the params variable. For example on your form, you access the data on the controller through the params[:name] and the params[:email]. You can do this: def create When you use the rails built in method to generate the form, if you look the html source code you will see: <input name="model[name]" /><input name="model[email]" /> When the form is submitted, the params hash will be: params = { Then, you can DRY up your controller def create Because the params[:model] will return the the hash and pass it direct to the constructor of your model, populating your data. I think it’s explain the Rails magic =) |
|
Authority 75
Posting Rating 0
Sign in to rate this post
|
You need some knowledge about Form Helpers. A good start point are the Rails Guides |
Authority 37
Posting Rating 0
Sign in to rate this post
|
Your going to likely run into this error http://stackoverflow.com/questions/435373/session-problem-in-rails-2-2-actioncontrollerinvalidauthenticitytoken-in-user, if you don’t use the form helpers or at least know what form fields the controller requires to be present in order for you to accomplish this. |
|
Authority 25
Posting Rating 0
Sign in to rate this post
|
rails docs may help you… |
Ask a Rails expert : nested application ApplicationController get called intead of children::ApplicationController
Ask a Rails expert : Best way to structure a database for a large/static dataset
Ask a Rails expert : Ruby Developer (ROR) - Scottish based (Remote working from within the UK)
Ask a Rails expert : Above Ground Pool Supplies
Ask a Rails expert : How to get url params in observer or model in Rails 3.1
Ask a Rails expert : What can persuade you to hire Junior Ruby devs with significant PHP experience?
Ask a Rails expert : What industry value does the Ruby or Rails Certification currently have?
Ask a Rails expert : Louis Vuitton Damier Azur Canvas specially sale ( www.salecheaplouisvuitton.com )
Ask a Rails expert : ·How to check errors/puts statements from ruby files which are under cronob
Ask a Rails expert : Louis Vuitton cheap Soft Sided Luggagespecial offer( www.salecheaplouisvuitton.com )