I'm a newbie for jRuby/Ruby on Rails and trying to create a website (Learning purpose).
In this web application users need to register to the system. Upon successful login attempt they are allowed to maintain their own dashboard which is a simple phone contact details management.
I'm using
jruby 9.0.5.0 (2.2.3)Rails 4.2.6Windows 10MySQLinXAMPPinstallation
Question no 1
In my signup, when I try to insert a new user, function works but I'm not getting the values in my textfields. Instead I'm getting null values in my table. What am I doing wrong?
This is my create User
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.timestamps null: false
end
end
end
This is my user.rb model
class User < ActiveRecord::Base
begin
attr_accessor :name, :email, :password, :password_confirmation
end
validates :name, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true
validates :password, :confirmation => true #password_confirmation attr
validates_length_of :password, :in => 3..20, :on => :create
end
This is my users_controller.rb
class UsersController < ApplicationController
def login
end
def create
flash[:notice] = ''
@user=User.new(user_params)
if @user.valid?
@user.save
flash[:notice] = "You signed up successfully"
render 'users/login'
else
flash[:error] = "Form is invalid"
render 'users/signup'
end
end
def signup
@user = User.new
flash[:notice]=''
flash[:error]=''
end
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end
This is my signup.html.erb
<div class = "content">
<h1>Sign Up</h1>
<p>Maecenas nisi nunc, vulputate ac tempus eget, suscipit ut sapien. Aenean fringilla ultricies ultricies.
Mauris aliquet nunc in velit posuere, in convallis purus ullamcorper.
Nam imperdiet lacus lacus, quis finibus diam dapibus a. Nullam quis accumsan libero. </p>
<div class = "form_data">
<%= form_for(:user, :url => {:controller => 'users', :action => 'create'}) do |f| %>
<table>
<tbody>
<tr>
<td> Name : </td>
<td> <%= f.text_field :name %> </td>
</tr>
<tr>
<td> Email : </td>
<td> <%= f.text_field :email %> </td>
</tr>
<tr>
<td> Password : </td>
<td> <%= f.password_field :password %> </td>
</tr>
<tr>
<td> Re-type Password : </td>
<td> <%= f.password_field :password_confirmation %> </td>
</tr>
<tr>
<td> </td>
<td> <%= f.submit :signup %> </td>
</tr>
</tbody>
</table>
<% end %>
</div>
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
</div>
Question no 2
How to create a contact_details table (id, name, phonenumber, owner_id) with user_ID of the user table as the foreign key (owner_id).
Question no 3
How to create the login algorithm nice and neat. Any links to a tutorial is appreciated
Question no 4
How to edit the Select queries in Jruby/Ruby on rails so that I can get the details based on the logged user.