0

When I press new on my Jobs form in seeing an error that it could not find 'create' in my JobsController.

Unknown action

The action 'create' could not be found for JobsController

Here' my controller:

class JobsController < ApplicationController

  private
  def load_clients
        @clients = collection_select :client, :client_id
  end

  def index
    @job = Job.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @job }
    end
  end

  def create
    @job = Job.new(params[:job])

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

  def show
    @job = Job.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @job }
    end
  end
end

As you can see. It' clearly there. Why is Rails not seeing it?

1 Answer 1

5

It is because you assign the create method as private.

Try redefine your controller this way.

Here' my controller:

class JobsController < ApplicationController

  def index
    ...
  end

  def create
    ...
  end

  def show
    ...
  end

  private

  def load_clients
    @clients = collection_select :client, :client_id
  end

end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.