Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:53:13+00:00 2026-06-08T14:53:13+00:00

user.rb class User < ActiveRecord::Base # attr_accessible :title, :body #validate :username ,:first_name ,:last_name ,:email

  • 0

user.rb

class User < ActiveRecord::Base
  # attr_accessible :title, :body
  #validate :username ,:first_name ,:last_name ,:email ,:password ,:phone ,:location ,:require => true
#  validates :username,:require => true
  validates :username, :presence => true
  has_many :ads 

  #validates :phone , :presence => true
  attr_accessor :password,:password_confirmation
  validates_confirmation_of :password
  attr_protected :hashed_password ,:salt

users_controller

  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = 'User successfully created.'
      redirect_to :action => 'index'
    else
      render :action => 'index'
    end
  end
  def new
    if session[:user_id]
      flash[:notice] = "You have already registered"
      redirect_to(:controller => 'main',:action => 'index')
    end
    @user = User.new

  end
  alias :register :new

registration_form

            <%= form_for @user do |f| %>
                <%= f.error_messages %>
        <table>
            <tr>
                <th>
                        <%= f.label :first_name %>
                </th>
                <td>
                        <%= f.text_field :first_name ,:placeholder => 'Please enter your real name.' %><br/>
                </td>
            </tr>
            <tr>
                <th>
                        <%= f.label :last_name %>
                </th>
                <td>
                        <%= f.text_field :last_name ,:placeholder => 'Please enter your real name.' %><br/>
                </td>
            </tr>
            <tr>
                <th>
                    <%= f.label :username  %>

                </th>
                <td>
                    <%= f.text_field :username ,:placeholder => 'Enter your username here'%>
                </td>
            </tr>
            <tr>
                <th>
            <%= f.label :email%>            
                </th>
                <td>
                <%= f.text_field :email ,:placeholder => 'sample@sample.com'  %><br/>       
                </td>
            </tr>

            <% if !session[:user_id] %>
                <tr>
                    <th>
                            <%= f.label :password %>
                    </th>
                    <td>
                            <%= f.password_field :password  ,:placeholder => 'EnterPassword' %><br/>
                    </td>
                </tr>
                <tr>
                    <th>
                            <%= f.label :password_confirmation,'Confirm Password' %>
                    </th>
                    <td>
                            <%= f.password_field  :password_confirmation  ,:placeholder => 'Confirm password' %><br/>
                    </td>
                </tr>
            <% end %>


            <tr>
                <th>
                        <%= f.label :phone %>
                </th>
                <td>
                        <%= f.text_field :phone  ,:placeholder => '09351270000' %><br/>
                </td>
            </tr>
            <tr>
                <th>
                        <%= f.label :location %>
                </th>
                <td>
                        <%= f.text_field :location  ,:placeholder => 'Your address' %><br/>
                </td>
            </tr>
            <tr>
            <td></td>   <td>    <%= f.submit !session[:user_id] ? 'Register' : 'Save changes',:class => 'button',:style => 'height:50px' %></td>
            </tr>
        </table>
            <% end %>

doubt

when i am logging in and updating user information using the same form its working fine , but when i am creating new user , i am redirected to users/index , while i am supposed to be registered

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:53:15+00:00Added an answer on June 8, 2026 at 2:53 pm

    This basically means that the @user.save fails. There can be many reasons for this, it is hard to tell exactly what this is, since you don’t give any error messages. The most probable case, I think, you are running into now is that you are trying to set a field (column of the user model) which is not accessible by the attr_accessible field.

    Since you have commented that line out you are telling rails that there exists no fields in the user model which can be mass assigned. This is what happens when you call User.create(params[:user])

    So to fix you problem now, try uncommenting your attr_accessible and add all the fields you need to set a user. In your case this would be:

    attr_accessible :first_name, :last_name, :username, :email, :password, :phone, :location
    

    I suggest you find some information on what attr_accessible and these others do. It is handy to know how these work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have two models: User and Teacher : class User < ActiveRecord::Base attr_accessor :password
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names has_many
I've two models: The first model: class Url < ActiveRecord::Base attr_accessible :code, :target, :user_id,
I have 2 models: Video: class Video < ActiveRecord::Base belongs_to :user has_many :thumbnails attr_accessor
class User < ActiveRecord::Base has_attached_file :photo, :styles => { :square => 100%, :large =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.