Information not getting into the controller from the view. (authologic model)

Posted by Gotjosh on Stack Overflow See other posts from Stack Overflow or by Gotjosh
Published on 2010-06-14T13:23:16Z Indexed on 2010/06/14 16:32 UTC
Read the original article Hit count: 129

Filed under:
|
|

Right now I'm building a project management app in rails, here is some background info:

Right now i have 2 models, one is User and the other one is Client. Clients and Users have a one-to-one relationship (client -> has_one and user -> belongs_to which means that the foreign key it's in the users table)

So what I'm trying to do it's once you add a client you can actually add credentials (add an user) to that client, in order to do so all the clients are being displayed with a link next to that client's name meaning that you can actually create credentials for that client.

So in order to do that I'm using a helper the link to helper like this.

<%= link_to "Credentials", 
        {:controller => 'user', :action => 'new', :client_id => client.id} %>

Meaning that he url will be constructed like this:

http://localhost:3000/clients/2/user/new

By creating the user for the client with he ID of 2.

And then capturing the info into the controller like this:

@user = User.new(:client_id => params[:client_id])

The weird thing is that EVERY other information BUT the client id it's getting passed and the client ID should be passed with the params[:client_id]. Any ideas? Perhaps it may have something to do with the fact that model User has "acts_as_authentic" because I'm using authologic for it?

Model:

class User < ActiveRecord::Base
  acts_as_authentic
  belongs_to :client
end

Controller:

def create
  @user = User.new(:client_id => params[:client_id])
  if @user.save
    flash[:notice] = "Credentials created"
  else
    flash[:error] = "Credentials failed"
  end
end

View:

<% form_for @user do |f| %>

<p>
    <%= f.label :login, "Username" %>
    <%= f.text_field :login %>
</p>

<p>
    <%= f.label :password, "Password" %>
    <%= f.password_field :password %>
</p>

<p>
    <%= f.label :password_confirmation, "Password Confirmation" %>
    <%=  f.password_field :password_confirmation %>
</p>

Let me know if this is sufficient or need more.

<%= f.submit "Create", :disable_with => 'Please Wait...' %>

<% end %>

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby