Difference between string and text in rails?

The difference relies in how the symbol is converted into its respective column type in query language. with MySQL :string is mapped to VARCHAR(255) https://edgeguides.rubyonrails.org/active_record_migrations.html :string | VARCHAR | :limit => 1 to 255 (default = 255) :text | TINYTEXT, TEXT, MEDIUMTEXT, or LONGTEXT2 | :limit => 1 to 4294967296 (default = 65536) Reference: Working … Read more

Undo scaffolding in Rails

First, if you have already run the migrations generated by the scaffold command, you have to perform a rollback first. rake db:rollback You can create scaffolding using: rails generate scaffold MyFoo (or similar), and you can destroy/undo it using rails destroy scaffold MyFoo That will delete all the files created by generate, but not any … Read more

How to redirect to a 404 in Rails?

Don’t render 404 yourself, there’s no reason to; Rails has this functionality built in already. If you want to show a 404 page, create a render_404 method (or not_found as I called it) in ApplicationController like this: def not_found raise ActionController::RoutingError.new(‘Not Found’) end Rails also handles AbstractController::ActionNotFound, and ActiveRecord::RecordNotFound the same way. This does two … Read more

Rails DB Migration – How To Drop a Table?

You won’t always be able to simply generate the migration to already have the code you want. You can create an empty migration and then populate it with the code you need. You can find information about how to accomplish different tasks in a migration here: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html More specifically, you can see how to drop … Read more

Ruby on Rails Server options [closed]

The word “deployment” can have two meanings depending on the context. You are also confusing the roles of Apache/Nginx with the roles of other components. Historic note: This article was originally written on November 6, 2010, when the Ruby app server ecosystem was limited. I’ve updated this article on March 15 2013 with all the … Read more

Begin, Rescue and Ensure in Ruby?

Yes, ensure ensures that the code is always evaluated. That’s why it’s called ensure. So, it is equivalent to Java’s and C#’s finally. The general flow of begin/rescue/else/ensure/end looks like this: begin # something which might raise an exception rescue SomeExceptionClass => some_variable # code that deals with some exception rescue SomeOtherException => some_other_variable # … Read more

tech