0

我正在尝试将我的应用程序植根于资源的新操作。

路线.rb:

  resources :competition_entries, :only => [:new]
  devise_for :users

  root 'competition_entries#new'

  namespace :admin do |admin|
    resources :competition_entries, :only => [:new, :index, :show]
  end

  #redirect all unknown routes to home
  match '*path' => redirect('/'), via: :get

竞争控制器.rb:

class CompetitionEntriesController < ApplicationController
  before_filter :authenticate_user!
  before_action :set_competition_entry, only: [:show, :edit, :update, :destroy]

  # GET /competition_entries
  # GET /competition_entries.json
  def index
    if current_user.admin?
      @competition_entries = CompetitionEntry.all
    else
      @competition_entries = current_user.competition_entries
    end
  end

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

  # GET /competition_entries/new
  def new
    @competition_entry = CompetitionEntry.new
    @competition_entry.build_address
    #@competition_entry.participants.build
  end

  # GET /competition_entries/1/edit
  def edit
  end

  # POST /competition_entries
  # POST /competition_entries.json
  def create
    @competition_entry = CompetitionEntry.new(competition_entry_params.permit!)
    #solves a minor issue when POST view is rendered
    @competition_entry.build_address(competition_entry_params[:address_attributes])

    respond_to do |format|
      if @competition_entry.save

        current_user.competition_entries << @competition_entry

        format.html { redirect_to @competition_entry, notice: 'Application was successfully created.' }
        format.json { render action: 'show', status: :created, location: @competition_entry }
      else
        format.html { render action: 'new' }
        format.json { render json: @competition_entry.errors, status: :unprocessable_entity }
      end
    end
  end

我得到的错误:

undefined method `competition_entries_path' for #<#<Class:0xb56e863c>:0xb5707e60>

 <%= nested_form_for(@competition_entry) do |f| %> << error points this line
<div class="row span10 center">

现在有人可以告诉我指的是什么吗?我只看到“@competition_entry”,并且删除了所有“competition_entries_path”变量。

谢谢。

4

0 回答 0