Sign Up Form Error: undefined method `model_name' for NilClass:Class

大憨熊 提交于 2019-12-12 02:04:13

问题


So this is my first attempt kind of just going without tutorial direction on building a site on RoR. Running into some trouble setting up my email signup form. I think there is an issue with how my model is setup or connected but not too sure. Getting "undefined method `model_name' for NilClass:Class" as the error".

signup.rb

class Signup < ActiveRecord::Base
    validates_presence_of :email

    def change
        create_tabe :quotes do |t|

            t.string :email
        end
    end

end

signups_controller.rb

class SignupsController < ApplicationController

    def new
        @signup = Signup.new
    end

    def create
        @signup = Signup.new(secure_params)
        if @signup.valid?
            redirect_to root_path
        else
            render :new
    end

    private

    def secure_params
        params.require(:signup).permit(:email)
    end

end

simple form section of the view

<%= simple_form_for @signup do |f| %>
  <%= f.input :email %>
  <%= f.submit 'Signup', :class => 'btn btn-success' %>
<% end %>

routes.rb

Rails.application.routes.draw do

  root 'pages#index'
  get '/about' => 'pages#about'
  get '/tour' => 'pages#tour'
  get '/music' => 'pages#music'

  resources :signups, only: [:new, :create]
end

Thanks for any and all help!


回答1:


<%= simple_form_for @signup do |f| %> 
to 


<%= simple_form_for :signup  do |f| %> 

For now it will not throw any error because of symbol :signup but for submit the form you need the action attributes for that you can use like url: { action: "create" } click for more detail

Hope this help you.



来源:https://stackoverflow.com/questions/28363650/sign-up-form-error-undefined-method-model-name-for-nilclassclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!