Home Ruby on Rails ActionController::UrlGenerationError in PersonelsController#create No route matches
Reply: 1

Ruby on Rails ActionController::UrlGenerationError in PersonelsController#create No route matches

Ezel
1#
Ezel Published in 2018-01-12 22:53:22Z

ActionController::UrlGenerationError in PersonelsController#create No route matches {:action=>"show", :controller=>"personels", :id=>nil}, missing required keys: [:id]
Extracted source (around line #31):

respond_to do |format|
  if @personel.save
    format.html { redirect_to @personel, notice: 'Personel was successfully created.' }
    format.json { render :show, status: :created, location: @personel }
  else
    format.html { render :new }

After creating the "Personel" I get such an error. There is no problem in the process. "Personel" added.I dont have idea about it.

class PersonelsController < ApplicationController
  before_action :set_personel, only: [:show, :edit, :update, :destroy]

  console

  # GET /personels
  # GET /personels.json
  def index
    @personels = Personel.all
  end

  # GET /personels/1
  # GET /personels/1.json
  def show
  end

  # GET /personels/new
  def new
    @personel = Personel.new
  end

  # GET /personels/1/edit
  def edit
  end

  # POST /personels
  # POST /personels.json

  def create
    @personel = Personel.new(personel_params)

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

  # PATCH/PUT /personels/1
  # PATCH/PUT /personels/1.json

  def update
    respond_to do |format|
      if @personel.update(personel_params)
        format.html { redirect_to @personel, notice: 'Personel was successfully updated.' }
        format.json { render :show, status: :ok, location: @personel }
      else
        format.html { render :edit }
        format.json { render json: @personel.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /personels/1
  # DELETE /personels/1.json
  def destroy
    @personel.destroy
    respond_to do |format|
      format.html { redirect_to personels_url, notice: 'Personel was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_personel
      @personel = Personel.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def personel_params
      params.require(:personel).permit(:name, :surname, :tc_no, :date_of_start, :date_of_finish, :department_id, :job_rotation_id)
    end
end

This is my route

Rails.application.routes.draw do
  resources :personels
  resources :job_rotations
  resources :departments
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Michael Arkhipov
2#
Michael Arkhipov Reply to 2018-01-13 01:25:10Z

Try using redirect_to path, like:

redirect_to personel_path(@personel)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309941 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO