I am building my first useful Rails application for a teacher to post assignments and students to upload their work (jpeg pdf) on the website using Carrierwave.
tutorial I want to replicate: http://ift.tt/2chnDAM
Error: "First argument in form cannot contain nil or be empty"
Error message: Extracted source (around line #14):
13 <div class = "well">
14 <%= form_for @submits, html: { multipart: true } do |f| %>
15 <%= f.label :name %>
16 <%= f.text_field :name %>
17 <%= f.label :attachment %>
model: submit.rb
class Submit < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model.
validates :name, presence: true # Make sure the owner's name is present.
end
controller: submit_controller.rb
class SubmitController < ApplicationController
def index
@submits = Submit.all
end
def new
@submit = Submit.new
end
def create
@submit = Submit.new(submit_params)
if @submit.save
redirect_to submits_path, notice: "The assignment #{@submit.name} has been uploaded."
else
render "new"
end
end
def destroy
@submit = Submit.find(params[:id])
@submit.destroy
redirect_to submits_path, notice: "The assignment #{@submit.name} has been deleted."
end
private
def submit_params
params.require(:submit).permit(:name, :attachment)
end
end
routes:
Rails.application.routes.draw do
resources :submit, only: [:index, :new, :create, :destroy]
get 'welcome/index'
get 'welcome/about'
root 'welcome#index'
end
schema:
ActiveRecord::Schema.define(version: 20160903040246) do
create_table "submits", force: :cascade do |t|
t.string "name"
t.string "attachment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
Thanks in advance to all the wonderful people here who are willing to lend a helping hand
Aucun commentaire:
Enregistrer un commentaire