Isaac Tait

Joined

1,870 Experience
18 Lessons Completed
0 Questions Solved

Activity

I was getting the error: Error: Form responses must redirect to another location in my dev tools (and the change password button was also not throwing any flash messages). I had to add status: :unprocessable_entity to my passwords_controller.rb file. Full code:

class PasswordsController < ApplicationController 
    before_action :require_user_logged_in!

    def edit
    end

    def update
        if Current.user.update(password_params)
           redirect_to root_url, notice: 'パスワードを変更しました'
       else
           render :edit, status: :unprocessable_entity
       end
    end

    private

    def password_params
        params.require(:user).permit(:password, :password_confirmation)
    end
end 

The problem was on line 11. It was flash.now.alert = "Invalid email or password." but it should have been flash[:alert] = "Invalid email or password" strike 112 for GitHub CoPilot

Posted in Rails for Beginners Part 17: Login Form Discussion

My sign_in page button is not working (I am not getting any flash messages). At first I thought it might have been related to Lesson 14, which I resolved by adding status: :unprocessable_entity (see my comment at at https://gorails.com/episodes/rails-for-beginners-part-14-handling-sign-up-errors) but that did not fix it. Here is my code (fyi - I am using TailwindsCSS instead of Bootstrap):

<div class='max-w-6xl mx-auto flex flex-col'>
    <h1 class='font-semibold text-2xl text-center mb-4'>Sign In</h1>

    <%= form_with url: sign_in_path, local: true do |form| %>
        <form class="w-full max-w-sm mb-4">
            <div class="md:flex md:items-center mb-6">
                <div class="md:w-1/3">
                <label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="inline-full-name">
                    Email
                </label>
                </div>
                <div class="md:w-2/3">
                <input class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" id="inline-full-name" type="text" value="Jane Doe">
                </div>
            </div>
            <div class="md:flex md:items-center mb-6">
                <div class="md:w-1/3">
                <label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="inline-password">
                    Password
                </label>
                </div>
                <div class="md:w-2/3">
                <input class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" id="inline-password" type="password" placeholder="******************">
                </div>
            </div>
            <div class="md:flex md:items-center">
                <div class="md:w-1/3"></div>
                <div class="md:w-2/3 mb-4">
                    <div class="text-center shadow bg-indigo-500 hover:bg-purple-400 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded" type="button">
                        <%= form.submit "Sign In" %>
                    </div>
                </div>
            </div>
        </form>
    <% end %>
</div>

As an aside I am getting this error in the dev tools too:

Uncaught TypeError: Error resolving module specifier “application”. Relative module specifiers must start with “./”, “../” or “/”.

I am not sure what is "breaking" my Sign In" button, any pointers on resolving would be greatly appreciated. Cheers

I was getting this error in my dev tools Error: Form responses must redirect to another location anytime I hit the form submit button. However, Michael's comment above helped me sort it out. I needed to add status: :unprocessable_entity to my registrations_controller.rb file. The full code looks like this:

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

    def create
        @user = User.new(user_params) 
        if @user.save
            session[:user_id] = @user.id
            redirect_to root_path, notice: "Thank you for signing up!"
        else
            render :new, status: :unprocessable_entity
        end
    end

    private

    def user_params
        params.require(:user).permit(:email, :password, :password_confirmation)
    end
end

I had the same error and I was also getting

PG::UndefinedTable: ERROR:  relation "users" does not exist (ActiveRecord::StatementInvalid)
LINE 9:  WHERE a.attrelid = '"users"'::regclass

when I was running User.create.... I had missed the command rails db:migrate 😫

I found a comment from a user having the same issue in the "Install Ruby & Rails Guide" above. The following fixed the issue for me:

After setting the global version, I needed to close the terminal, open another, run rbenv rehash.

I ran rbenv install 3.0.3 (followed by rbenv global 3.0.3) and it returned the following:

Downloading openssl-1.1.1l.tar.gz...
-> dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...
Installed openssl-1.1.1l to /Users/isaactait/.rbenv/versions/3.0.3

Downloading ruby-3.0.3.tar.gz...
-> cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.3.tar.gz
Installing ruby-3.0.3...
ruby-build: using readline from homebrew
Installed ruby-3.0.3 to /Users/isaactait/.rbenv/versions/3.0.3

However, when I run ruby -v it returns ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]

Why am I running a version I did not install? On a Mac 12.2.1

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.