问题
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