Desk2Mob

Desk2Mob

Desk2Mob

Programming Languages

How to rollback Rails database migrations?

To rollback your most recent migration, execute the command below rake db:migrate:rollback If you want to rollback a specific migration, you need to execute the command below rake db:migrate VERSION=

Posted on February 03, 2014 by Amit Pandya
Model vs. Scaffold?

A model just generates the model. Scaffold generates a controller and views, too. ./script/generate model mymodelname creates an ActiveRecord model that is typically connected to a database, but doesn't have to be. ./script/generate scaffold scaffoldname creates a model, a controller, a layout, some CSS styles, and more. This provides you with the model and everything else needed to work with it. This doesn't mean that scaffolding should be used all the time; it is good for quick development, but it isn't customizable enough and isn't intended for use in a production environment.

Posted on February 03, 2014 by Amit Pandya
How to change the default port in WEBrick?

Rails starts its web server on port 3000 by default. If you want to use a different port, such as 8888, run the command below. ruby script/server -p 8888

Posted on February 03, 2014 by Amit Pandya
How to create a Rails application for a specific Rails version?

If you have multiple Rails versions installed on your application, and if you want to create a Rails application using the command below rails demo_apps In this case, it will create a Rails application "apps" with the latest version installed on our machine. If you want to create a Rails application for specific Rails versions, use the command below rails _x.x.x_ appname example of rails _2.2.2_ demo_apps Please make sure there is a space after rails. A new app has been created with the 2.2.2 codebase

Posted on February 03, 2014 by Amit Pandya
Difference between <% %> and <%= %> ?

&lt;% .... %&gt; is Scriptlet and &lt;%= ... %&gt; is Expression

Posted on February 03, 2014 by Amit Pandya
Ruby - String Class

Ruby - String Class

Posted on February 21, 2014 by Amit Pandya
Upgrade from Ruby 2.3.3 to Ruby 2.4.0

In Ruby 2.4.0, the Fixnum and Bignum classes were merged into Integer, resolving a long-standing issue. Fixnum for small integers (range depends on implementation, usually limited to machine word size) Bignum for larger integers (arbitrary precision) Let’s see this in action. Ruby 2.3.3 $ ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16] $ irb &gt;&gt; 4.class =&gt; Fixnum &gt;&gt; (2**62).class =&gt; Bignum two integer classes are both subclasses of Integer. &gt;&gt; 4.class.superclass =&gt; Integer &gt;&gt; (2**62).class.superclass =&gt; Integer So, in Ruby 2.3.3: Small numbers → Fixnum Large numbers → Bignum Both inherit from Integer Ruby 2.4.0 Now, let’s see what occurs in Ruby 2.4.0: $ ruby -v ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16] $ irb &gt;&gt; 4.class =&gt; Integer &gt;&gt; (2**62).class =&gt; Integer No matter how small or large the number is, Ruby now uses In...

Posted on January 04, 2017 by Amit Pandya
Single quotes and double quotes in Python

Single quotes and double quotes in Python In Python, single quotes and double quotes create the same kind of string. These two lines are equivalent: foo = "bar" foo = 'bar' If Jupyter or the Python console shows the value as 'bar', that does not mean Python changed your double quotes into single quotes. The console is showing the string representation, also called repr. Python often chooses single quotes when displaying that representation. foo = "bar" foo # 'bar' print(foo) # bar So which one should you use? Use either single quotes or double quotes for normal strings. Be consistent inside the same project or file. Use double quotes when the string contains a single quote. Use single quotes when the string contains double quotes. Use triple double quotes for docstrings. Good examples message = "It's working" html = '&lt;p class="title"&gt;Hello&lt;/p&gt;' def hello(): """Return a greeting message.""" return "Hello" There ...

Posted on June 08, 2026 by Amit Pandya