You can find more regarding Rails Migrations here. Whats the difference between string and text And when should each one be used Quite simply, the difference relies in how the symbol is converted into its. In this case, we will add a DatabaseCleaner block to railshelper.rb so that each each test will run in an empty database. They can be used to customize rspec to your application needs. called products with a string column called name and a text column called description. rails generate rspec:install This command will create a spec folder and add spechelper.rb and railshelper.rb to it. Then it will set character limit for the ‘description’ column to 50 and it will not allow to enter information having length more than 50 characters for that column. The methods Active Record provides to manipulate your database. Then in Rails, we can write migration as follows, class CreatePosts 50 Let us create a sample table ‘posts’ having following fields There are several ways how to disable this automatic escaping. then you may want to consider Text as a column type for the same. Sometimes, Rails’ built-in auto escaping feature might not be desirable because of some business need, and actually we may intentionally want to output data that contains legit HTML through views. if you want to store description, content of some post etc. When to use Text for column type?Ĭolumn type should be used as String when you want to store much more characters (No Limit - not literally) e.g. Inference When to use String for column type?Ĭolumn type should be used as String when you want to store characters with length fairly minimum unto 255.
0 Comments
Leave a Reply. |