Forum: Ruby on Rails =?iso-8859-1?q?User=2Enew_doesn=B4t_capture_all_of_the_p?= =

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3b1daae9f655c5dba51ff1cdf03f1bef?d=identicon&s=25 Martin Stabenfeldt (Guest)
on 2006-05-09 13:42
(Received via mailing list)
Hi,

I have a page where I can add new users to the database, but it only
sees whats in the name and passord field.

add_user.rhtml:
	<%= form_tag %>
	<%= form_tag :action => 'add_user' %>

	<td>User name:</td>
	<td><%= text_field("user", "name") %></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><%= password_field("user", "password") %></td>
	</tr>
	<tr>
     	<td>Company:</td>
     	<td><%= text_field("user", "company") %></td
<tr>

The database looks like this:
create table users (
	id      int           not null auto_increment,
	name    varchar(100)	not null,
	company varchar(100)  not null,
	ownnumber int					not null,
	sendt   int           not null,
	count   int           not null,
	msg_limit		int           not null,
	access_level		varchar(50)   not null,
	hashed_password	char(40)	not null,
	primary key	(id)
);

login_controller.rb:

   def add_user
     if request.get?
       @user = User.new
     else

       @user.company = (params[:user][:company])		# Tried first
without this line, since I didn´t see any for name and password.
												# I hoped the one below would capture all the fields.

       @user = User.new(params[:user])				# How come this doesn't
manage to save whats in "company", "ownnumber" etc. ?

       puts "DEBUG: add_user() user is  #{@user.name} from the
company #{@user.company}, count is #{@user.count}" # this is empty
       if @user.save

         redirect_to(:controller => "numbers", :action => "index")

       end
     end
   end

Debug info:
Parameters: {"user"=>{"name"=>"test3", "company"=>"family",
"ownnumber"=>"555983781", "count"=>"10", "access_level"=>"",
"password"=>"SECRET"}}

How come  @user = User.new(params[:user] doesn´t saves whats in
"company", "count" etc. ?


I´ll be very grateful to everyone that comes with suggestions or hint
on what I´m doing wrong!



Kind regards,
Martin Stabenfeldt
9ab183bb240ffd3a3966d5a615b4bdeb?d=identicon&s=25 Philip Ross (Guest)
on 2006-05-09 23:34
(Received via mailing list)
Martin Stabenfeldt wrote:
> Debug info:
> Parameters: {"user"=>{"name"=>"test3", "company"=>"family",
> "ownnumber"=>"555983781", "count"=>"10", "access_level"=>"",
> "password"=>"SECRET"}}
>
> How come  @user = User.new(params[:user] doesn´t saves whats in
> "company", "count" etc. ?

Are you using attr_accessible or attr_protected in your User model? If
you are, you'll need to adjust them to allow company, count, etc to be
mass-assigned.

See the API docs for more information:

http://api.rubyonrails.org/classes/ActiveRecord/Ba...

--
Philip Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
3b1daae9f655c5dba51ff1cdf03f1bef?d=identicon&s=25 Martin Stabenfeldt (Guest)
on 2006-05-10 10:58
(Received via mailing list)
Hi,
This topic is locked and can not be replied to.