Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

rails crud

class ArticlesController < ApplicationController
  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end

  def new
    @article = Article.new
  end

  def create
    @article = Article.new(article_params)

    if @article.save
      redirect_to @article
    else
      render :new, status: :unprocessable_entity
    end
  end

  def edit
    @article = Article.find(params[:id])
  end

  def update
    @article = Article.find(params[:id])

    if @article.update(article_params)
      redirect_to @article
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to root_path, status: :see_other
  end

  private
    def article_params
      params.require(:article).permit(:title, :body)
    end
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails g migration add column array 
Ruby :: httparty SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError) 
Ruby :: ruby pluck 
Ruby :: add column with default value in rails 
Ruby :: array to string ruby 
Ruby :: how to link to with font awesome rails 
Ruby :: how to make a new array ruby 
Ruby :: ruby not include 
Ruby :: ruby change directory 
Ruby :: attr_accessor ruby 
Ruby :: open url in ruby 
Ruby :: Rails validations: unique scope 
Ruby :: rails parse boolean 
Ruby :: ruby array 
Ruby :: ruby each 
Ruby :: font awesome rails 
Ruby :: rails 6 TypeError: $(...).tooltip is not a function 
Ruby :: ruby random number between 
Ruby :: ruby on rails array contains multiple values 
Ruby :: add index in rails 
Ruby :: rails assets video not found video_tag 
Ruby :: EOFError: end of file reached 
Ruby :: How to handle permission in rails 
Ruby :: my rails server exits automatically 
Ruby :: Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once per semester for a particular class. 
Ruby :: ruby md5 
Ruby :: simpleCov formatter set two formats 
R :: r how to import tsv file 
R :: suppress error r 
R :: how to select certain rows containing a word in r 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =