Invalid Authenticity Token Error After Filling out the Form


#1

I'm facing a similar problem! After filling out the form, the browser shows a page which says- Invalid Authenticity Token.

For your reference, here is my code from users_controller.rb:

class UsersController < ApplicationController
  
  def new
    @user = User.new
  end
  
  def create
    @user = User.new(user_params)
    if @user.save
      session[:user_id] = @user.id
      redirect_to '/'
    else
      redirect_to '/signup'
    end
  end
  
  private
  	def user_params
      params.require(:user).permit(:first_name, :last_name, :email, :password)
    end
end

Here is my code from users/new.html.erb -

<div class="login">
  <div class="container">
    <div class="form">

    <h1>Sign up</h1>

    <%= form_for(@user) do |f| %>
      <%= f.text_field :first_name, :placeholder => "First name" %>
      <%= f.text_field :last_name, :placeholder => "Last name" %>
      <%= f.email_field :email, :placeholder => "Email" %>
      <%= f.password_field :password, :placeholder => "Password" %>
      <%= f.submit "Create an account", class: "btn-submit" %>
    <% end %>

  
    </div>
  </div>
</div>

#2

Hi @saifalizafar,

Could you please post a link to the exercise you're on? I'm not sure what's causing this problem, and will probably need to do some digging to figure it out.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.