Can you help me with implementation CarrierWave in Rails
I had an error it says that NoMethodError in HomeworksController
and here my HomeworksController class:
class HomeworksController < ApplicationController
before_action :signed_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy
def create
@homework = current_user.homeworks.build(homework_params)
if @homework.save
flash[:success] = "Homework created!"
redirect_to root_url
else
@feed_items = []
render 'static_pages/home'
end
end
def new
@homework =Homework.new
end
def destroy
@homework.destroy
redirect_to root_url
end
def index
@homeworks=Homework.all
end
private
def homework_params
params.require(:homework).permit(:content, :attachment)
end
def correct_user
@homework = current_user.homeworks.find_by(id: params[:id])
redirect_to root_url if @homework.nil?
end
end
Comments
Leave a comment