# Beginner question about attributes

**URL:** <https://www.ruby-forum.com/t/beginner-question-about-attributes/155163>\
**Category:** Ruby\
**Created:** [December 8, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163 "2008-12-08T22:37:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 8, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/1 "2008-12-08T22:37:50Z")

</div>

I don’t understand why my model (attached) isn’t working.

I generated a scaffold for my ‘player’ data. If I uncomment the  
:validates\_presence\_of check in my model, the save on the ‘new’ page  
compalins about those fields, and re-displays them without the data I’ve  
typed in (along with the red surrounding and error messages, of course).

If I run the model as is, the save goes through, but none of the fields  
except hashed\_password get saved. Or, another way to put it is, the  
_only_ field that gets saved is the one I set manually in the  
before\_create handler.

I don’t understand what I did. I haven’t changed the generated view for  
new.html.erb, the column names haven’t changed in the database. I don’t  
see what’s missing to reconnect those elements.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 12:38am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/2 "2008-12-09T00:38:57Z")

</div>

On Dec 8, 3:31 pm, Scott P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I run the model as is, the save goes through, but none of the fields  
> except hashed\_password get saved. Or, another way to put it is, the  
> _only_ field that gets saved is the one I set manually in the  
> before\_create handler.

1. This is a Rails question, not a Ruby question.

2. This has probably much more to do with your controller than your  
model.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 12:51am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/3 "2008-12-09T00:51:10Z")

</div>

Yossef M. wrote:

> On Dec 8, 3:31?pm, Scott P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > If I run the model as is, the save goes through, but none of the fields  
> > except hashed\_password get saved. ?Or, another way to put it is, the  
> > _only_ field that gets saved is the one I set manually in the  
> > before\_create handler.

Thanks for the response. I guess there’s a lot I don’t understand.

> 1. This is a Rails question, not a Ruby question.

I thought that Ruby was the language in which all the controllers,  
models, and views were written. If I’ve generated a scaffold and only  
changed the model file, it seems like that’s where I’ve introduced the  
bug(?)

> 1. This has probably much more to do with your controller than your  
> model.

Something in the generated create, where it initializes as such:

@player = Player.new(params[:player]). I’ll keep poking around to see  
if I can figure out why those params aren’t what I think they should be.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 1:15am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/4 "2008-12-09T01:15:58Z")

</div>

Tim H. wrote:

> Scott P. wrote:
> 
> > I thought that Ruby was the language in which all the controllers,  
> > models, and views were written. If I’ve generated a scaffold and only  
> > changed the model file, it seems like that’s where I’ve introduced the  
> > bug(?)
> 
> You’re correct. However, Ruby is a general-purpose programming language  
> used for many things besides Rails. This list is generally frequented by  
> Ruby users of all stripes and, while there may be a few Rails users  
> around, you will have more luck getting an answer to your question in  
> the Rails forum.
> 
> See [Ruby on Rails — Community](http://www.rubyonrails.com/community)
> 
> Good luck!

Ah, thanks for the clarification. Yossef got me thinking down a  
different path, which led me to making those attributes accessible,  
seems to be working (well enough for me–as I learn more, I’ll probably  
figure out that needs to be changed).

Anyway, I appreciate the feedback.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 1:11am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/5 "2008-12-09T01:11:42Z")

</div>

Scott P. wrote:

> I thought that Ruby was the language in which all the controllers,  
> models, and views were written. If I’ve generated a scaffold and only  
> changed the model file, it seems like that’s where I’ve introduced the  
> bug(?)

You’re correct. However, Ruby is a general-purpose programming language  
used for many things besides Rails. This list is generally frequented by  
Ruby users of all stripes and, while there may be a few Rails users  
around, you will have more luck getting an answer to your question in  
the Rails forum.

See [Ruby on Rails — Community](http://www.rubyonrails.com/community)

Good luck!

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 1:28am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/6 "2008-12-09T01:28:40Z")

</div>

Scott P. wrote:

> Ah, thanks for the clarification. Yossef got me thinking down a  
> different path, which led me to making those attributes accessible,  
> seems to be working (well enough for me–as I learn more, I’ll probably  
> figure out that needs to be changed).
> 
> Anyway, I appreciate the feedback.

Don’t feel alone. We get one or two new Rails users a week, sometimes  
more. After you master Rails maybe you’ll want to use Ruby for something  
else. If so, come on back. We’ll still be here.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/7 "2008-12-09T16:38:48Z")

</div>

Scott P. wrote:

> I thought that Ruby was the language in which all the controllers,  
> models, and views were written. If I’ve generated a scaffold and only  
> changed the model file, it seems like that’s where I’ve introduced the  
> bug(?)

A technical question always gets the best answer on the narrowest  
possible  
forum. To help the Rails forum succeed, we who know Rails try not to  
answer  
questions about it here; that dilutes both groups.

> @player = Player.new(params[:player]). I’ll keep poking around to see  
> if I can figure out why those params aren’t what I think they should be.

How are your unit tests?

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 2:21am UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/8 "2008-12-09T02:21:15Z")

</div>

> After you master Rails maybe you’ll want to use Ruby for something  
> else.

Like RMagick 🙂

Or for complete world dominance.

I may have some script for that … world\_control.rb

It is unfinished though.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [December 9, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/beginner-question-about-attributes/155163/9 "2008-12-09T17:06:20Z")

</div>

On Dec 8, 6:09 pm, Scott P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ah, thanks for the clarification. Yossef got me thinking down a  
> different path, which led me to making those attributes accessible,  
> seems to be working (well enough for me–as I learn more, I’ll probably  
> figure out that needs to be changed).

To be honest, I didn’t really look closely at the model because I had  
already categorized this as a Rails question by that point.

There was no way to be absolutely positive given the information  
provided, but it could be reasonable to assume you were using a  
generated controller with standard actions. Really, the problem was in  
the model with the use of attr\_accessible, which keeps other  
attributes from being mass-assigned.

Of course, the question was still in the wrong place, much like  
attr\_accessible and attr\_protected are in the wrong part of the MVC  
trio. But that’s a discussion for another day.
