DEV Community

Discussion on: Choosing the Right Technology for SaaS Product Development: Benefits of Ruby on Rails

Collapse
 
guledali profile image
guledali • Edited

Did you know that dev.to/ is rails app?

But you asked a good question why rails? I'm going to skip 2020 because a few weeks from now it will be 2021. Again it really does not matter rails is already 15-16 years old and the truth is it will never be outdated the ideas around is what have formed the web.

An example

link_to "Profile", profile_path(@profile)
=> simply becomes <a href="/profiles/1">Profile</a>
Enter fullscreen mode Exit fullscreen mode

A simple anchor tag will do a full reload page request, I might be old fashion but this is how web was intended to be.

The MVC pattern which I think is one of the easiest way of designing apps on top of that the 7-resourceful-actions. Registrating a new user would looks something like this

# users_controller.rb
def create
  @user = User.new(params[:user])
  if @user.save
    session[:user_id] = @user.id
    redirect_to root_url, notice: "Thank you for signing up!"
  else
    render "new"
  end
end
Enter fullscreen mode Exit fullscreen mode

Those lines above is understandable even for someone that does not know anything about web development.

Rails is a web framework, as javascript developer that has been on three different jobs. It feels like I have to relearn each time how to simple things depending on choices that developers have done and so forth. One example being adding a simple validation to fields. If you ask a rails developer they know where to add that validation by heart

class Post < ApplicationRecord
   validates  :title,    presence: true
   validates  :content,  presence: true
end
Enter fullscreen mode Exit fullscreen mode

Now you can simply display that error

post = Post.new()
post.save
post.errors.full_messages.each { |error| puts error }
# => ActiveRecord::RecordInvalid: Validation failed: title can't be blank
# => ActiveRecord::RecordInvalid: Validation failed: content can't be blank
Enter fullscreen mode Exit fullscreen mode
Collapse
 
codicacom profile image
Codica

Thank you! We couldn't have put it better.