Installing authlogic 3.4.3 in Rails 4.1.7

149 views Asked by At

Since yesterday I have been trying to install authlogic in a project. As I can see, all the examples and the documentation are oriented to older versions of both rails and authlogic. However, I tried to follow :

the example in the documentation the railscast other websites examples like: http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/ (for me, the most useful tutorial until now) I don't get authlogic working properly. I installed the gem trough the gemfile and the bundle install order. I generated a model user and ran the migration

$ rails generate scaffold user username:string email:string crypted_password:string password_salt:string persistence_token:string $ rake db:migrate

I add the following line to the model user.rb:

acts_as_authentic

then, I put a link to register a new user: link_to "Register", new_user_path I edit /app/views/users/index.html.erb to look like:

<h1>Listing users</h1>

<table>
  <tr>
    <th>Username</th>
    <th>Email</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @users.each do |user| %>
  <tr>
    <td><%= user.username %></td>
    <td><%= user.email %></td>
    <td><%= link_to 'Show', user %></td>
    <td><%= link_to 'Edit', edit_user_path(user) %></td>
    <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New User', new_user_path %>

and app/views/users/_form.html.erb to look like:

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :username %><br />
    <%= f.text_field :username %>
  </div>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
  <div class="field">
    <%= f.label :password %><br />
    <%= f.password_field :password %>
  </div>
  <div class="field">
      <%= f.label :password_confirmation %><br />
      <%= f.password_field :password_confirmation %>
    </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Now, when I try to register an user, I get two errors:

-Password is too short (minimum is 4 characters)
-Password confirmation is too short (minimum is 4 characters)

I have put longer passwords but it doesn't work.

Any help?

Thank you

1

There are 1 answers

1
herestomwiththeweather On BEST ANSWER

Just based on the error messages without seeing the users controller, it appears that password and password_confirmation are not being passed to the user model. This may be a Rails 4 preventing mass assignment issue. To allow this, in the create method in the users controller, you can say:

@user = User.new(user_params)

and then define the user_params method:

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