Beginner question about attributes

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.

On Dec 8, 3:31 pm, Scott P. [email protected] 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.

Yossef M. wrote:

On Dec 8, 3:31?pm, Scott P. [email protected] 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.

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

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.

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

Good luck!

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.

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?

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

Like RMagick :slight_smile:

Or for complete world dominance.

I may have some script for that … world_control.rb

It is unfinished though.

On Dec 8, 6:09 pm, Scott P. [email protected] 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.