1

As you can guess from the question I am an extreme beginner at rails.

My question is that in /db/migrate where you create your tables, what are the t.string, t.integer, t.text etc. called and is there a list of the different types of t.something you can use?

Also I noticed that when creating a form_for in a view there is f.text_field, f.text_area etc. Are these f.something called the same thing as t.something and is there a list of the different types of f.something I can use. For instance can I use f.check_box?

Thank you for your time,

Brian

  • 1
    https://stackoverflow.com/questions/17918117/rails-4-datatypes Think that will do it? – Tim Jan 14 '16 at 22:37

2 Answers2

1

OK - first the list of t.types - these tell rails which types of columns to create in the database, and as rails uses these automagickally, also in the models you create. See Rails 4: List of available datatypes for the list.

Next up is the f.things - these are form helpers, you use them in your views, to generate html forms - read about them here: http://guides.rubyonrails.org/form_helpers.html

Suggest this post - Summary of Ruby on Rails fundamental concepts to get a view on what's going on, and maybe some online tutorials.. when you get stuck, then you come here.

Community
  • 1
  • 1
Tim
  • 1,005
  • 3
  • 10
  • 21
  • thanks Tim. Sorry I didn't know that they were called datatypes so i couldn't find it on here – Brian Hudson Jan 14 '16 at 23:13
  • No worries at all, if you don't know the concept names, then it makes searching out info very very difficult! I should add, that t. and f. don't mean anything, you can set things up as x.integer for a table migration and x.checkbox for a form, it's just easier to read. – Tim Jan 14 '16 at 23:15
0

This will tell you everything you could want to know about migrations.

http://edgeguides.rubyonrails.org/active_record_migrations.html

By convention the migration object is referred to as t as in

create_table :products do |t|

And then you reference the methods of that object within the block... t.string etc... but it doesn't have to be t you could use table or cabbage or whatever, as long as you use the argument variable passed in the do line you're fine.

This site explains about form helpers...

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

Again in this case the f references the argument at the beginning of the block. By convention we use f for form but you can use anything.

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53