2

I'm trying to save a string to the database and output it from the view. Just starting to learn RoR, so a bit confused here...

Here's what I did:

  • generate model test id :string value :string

followed by

  • rake db:migrate

then I opened the rails console from ./script/rails console

I'm trying to type this here:

test.create!(:value => "Hello World")

but it returns "ArgumentError: wrong number of arguments" :( How can I do this correctly? Also, how can I store this to a variable and output it in the view?

Thanks!

1
  • 1
    Try Test.create!(:value => "Hello World"). create is a class method. Commented Nov 29, 2012 at 4:38

1 Answer 1

4

Your model should start with an uppercase letter;

Test.create!(:value => 'a string')
Sign up to request clarification or add additional context in comments.

6 Comments

You're likely running into the fact that the name Test is already taken by Test::Unit, which is a part of Ruby.
exactly right - test is probably a reserved word. Also, what Kenrick was trying to point out is that you use the Propercase of the word for creating records on that model, Test not test.
Can you use a model name other than Test? You may be conflicting with some gem or class in your codebase? Try creating model like Book.
Hah - works now! Thanks so much, looks like I just ran into some teething problems :)
Also, how can I define a method in my controller so that this value is attached to a variable?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.