Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError in Users#new "undefined method `simple_form_for' for #<#<Class:0x9f9b568>:0xaa02440>"

My new.html.erb code in views/users:

 <h1>Sign Up</h1>

 <%= simple_form_for(@user) do |f| %>
 <%= f.input :username %>
 <%= f.input :password %>
 <%= f.input :password_confirmation %>
 <%= f.button :submit %>
 <% end %>

this is the error:

 undefined method `simple_form_for' for #<#<Class:0x9f9b568>:0xaa02440>

I know what this error is asking for:

 def simple_form_for
 end

but the problem is where to put it. Also this is my users_controller.rb:

 class UsersController < ApplicationController
     def new
          @user = User.new
     end

     def create
         @user = User.new(params[:user])
         if @user.save
             redirect_to @user, notice: 'User was successfully created.'
         else
             render action: "new"
         end
     end

     def show
         @user = User.find(params[:id])
     end
 end
like image 709
Yahs Hef Avatar asked Jan 17 '26 20:01

Yahs Hef


2 Answers

That's not what it's expecting at all.

simple_form_for means your app is expecting to have the Simple Form (https://github.com/plataformatec/simple_form) gem available, which provides that method for your forms to use. You should either install the gem, by adding it to your Gemfile, or rewrite your form to use Rails form helpers instead of Simple Form.

like image 89
sevenseacat Avatar answered Jan 20 '26 13:01

sevenseacat


If it does not find the method but you had installed the gem. In that case, I think you forgot to restart the server. Restart the server and it will work.

like image 35
Khoga Avatar answered Jan 20 '26 12:01

Khoga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!