简体   繁体   中英

Rails method to add record to db from the url

I'm new to rails I'd like to know how can I create a method to add the parameters from the URL to the database?

eg http://localhost:3000/myapp?name=John&age=32/

How can I insert the name parameter and then the age parameter into the db?

Basically, you could do (Given you crated a User model + it's migration):

User.create({:name => params[:name], :age => params[:age].to_i})

name and age attributes should be set as accessible in the User model.

But you should have a look at how the scaffold behave and also look at railsforzombies.org where you'll learn much!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM