I've been trying to build a simple login and sign up screen but the user data isn't saving when i hit submit button. This is the page in devise At first eveything was going well and i got rib of most of the errors on my own but ive been stuck with this for a week.
When i fill out the form and hit submit the url changes to "http://localhost:3000/users/sign_up?user%5Busername%5D=Madmax_123&user%5Bfname%5D=Maxwell&user%5Blname%5D=Ross&user%5Bdob%5D=2000-01-22&user%5Bemail%5D=madmax_maxwell%40outlook.com&user%5Bpassword%5D=madmax123&user%5Bpassword_confirmation%5D=madmax123&commit=Submit#"
i wasnt sure is this was a problem so i checked to see is any users were created after in console with @user = User.first but it keeps coming up >=nil
<div class="space">
<div class="wrapper">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="container2 right-panel-active" id="container2">
<div class="form-container2 sign-up-container2">
<form action="#" id="form">
</form>
</div>
<div class="form-container2 sign-in-container2">
<form action="#" id="form">
<h3 class="h1">Create Account</h3><br><br><br><br>
<%= f.text_field :username, autofocus: true, placeholder:"User Name", class:"input" %>
<%= f.text_field :fname, placeholder:"First Name", class:"input" %>
<%= f.text_field :lname, placeholder:"Last Name", class:"input" %>
<%= f.date_field :dob, placeholder:"Dte of Birth", class:"input" %>
<%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder:"Email", class:"input" %>
<%= f.password_field :password, autocomplete: "new-password", placeholder:"Password", class:"input" %>
<%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder:"Confirm Password", class:"input" %><br><br>
<%=f.submit "Submit", class:"button" %>
</form>
</div>
<div class="overlay-container2">
<div class="overlay">
<div class="overlay-panel overlay-left">
<h3 class="h1">Already have an Account?</h3><br> <br>
<%= link_to "Login", new_user_session_path, class:"ghost2" %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
I added the variables to my migration.
class CreateEvents < ActiveRecord::Migration[5.1]
def change
create_table :events do |t|
t.decimal :price
t.date :date
t.string :venue
t.string :ename
t.text :description
t.text :time
t.integer :ticket
t.timestamps
end
end
end
allowed for the variables to be passed in my application controller
require "application_responder"
class ApplicationController < ActionController::Base
self.responder = ApplicationResponder
respond_to :html
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :fname, :lname, :dob])
end
end
Event controller
class EventsController < ApplicationController
def index
end
def show
@event = Event.find(params[:event_id])
end
def new
end
def create
@event = Event.new(event_params)
@event.save
redirect_to events_url events_path
end
private def event_params
params.require(:event).permit(:ename, :price, :date, :venue, :description, :time, :ticket)
end
end
any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire