Ruby on Rails MVC & Full-Stack Development
18 mins read
Free Lesson
Define resource routes in config/routes.rb and sanitize inputs with params.require().permit().
RESTful Routing & Strong Parameters
# app/controllers/tutorials_controller.rb
class TutorialsController < ApplicationController
def index
@tutorials = Tutorial.where(is_free: true)
end
def create
@tutorial = Tutorial.new(tutorial_params)
if @tutorial.save
redirect_to @tutorial, notice: 'Tutorial created successfully!'
else
render :new, status: :unprocessable_entity
end
end
private
def tutorial_params
params.require(:tutorial).permit(:title, :content, :is_free)
end
end