0

As a noob, I have done this a few times, but I always struggle with the strong params. I rolled a new model and controller for uploading a link to a video.

Here is my code: new_vids_controller.rb

    class NewVidsController < ApplicationController
  def index
    @vids = NewVid.all
  end

  def new
    @vid = NewVid.new(vid_params)
  end

    def create
    if current_user
    @vid=NewVid.new(vid_params)
    @vid.user_id = current_user.id
        if @vid.save
            flash[:notice] = "Video Submitted"
                redirect_to videos_path
            else
                flash[:error] = "Error: Vid not Submitted"
                redirect_to videos_path
            end
        else
            flash[:error] = "You Must Be Signed In To Submit Videos!"
            store_location
            redirect_to signin_path
        end
  end

end

    private

    def vid_params
        params.require(:new_vid).permit(:vid_link, :vid_body, :user_id)

    end

new.html.erb

            <%= form_for @vid do |f| %>
              <%= f.text_field :vid_link, title: "Video Link", placeholder: "Video Link" %>
              <%= f.text_field :vid_body, title: "Description", placeholder: "Video Description" %>
              <%= f.submit "Submit Link", class: "button tiny" %>

Thanks for helping a noob!

Wasik
  • 35
  • 1
  • 5

1 Answers1

0

Your new action should be:

@vid = NewVid.new

There are no params to validate there.

BroiSatse
  • 44,031
  • 8
  • 61
  • 86