avatar
Untitled

Guest 77 21st Oct, 2019

                                           
                         ## A migration
class CreateIdeas < ActiveRecord::Migration[5.2]
  def change
    create_table :ideas do |t|
      t.string :name
      t.text :description

      t.timestamps
    end
  end
end

## Exemplo de metodo
# POST /ideas
# POST /ideas.json
  def create
    @idea = Idea.new(idea_params)

    respond_to do |format|
      if @idea.save
        format.html { redirect_to @idea, notice: 'Idea was successfully created.' }
        format.json { render :show, status: :created, location: @idea }
      else
        format.json { render json: @idea.errors, status: :unprocessable_entity }
      end
    end
  end

## parametros que o controller do rails usa em o metodos do CRUD para
## manipular os dados
private
    def idea_params
      params.require(:idea).permit(:name, :description)
    end
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data