Topic: Basic Database / relationship-question.
Hi. Im new here, well; im actually new to the whole rails-community!
I've looked at a couple of books so I should know pretty much, but that's not the case
Im having problem with the whole ActiveRecord class, adding data, recieve data, and relationships.
Im gonna do some pseudocode since im not at my developer-machine at the moment, I hope that's alright.
What i want to do is simple:
I want to add text and comments to a database and in "list.rhtml" list _all_ posts and at "show.rhtml" list all comments for the right post.
I started to by creating two tables and two models.
Posts (id, message) - post.rb:
Comments (id, comment, post_id) - comment.rb
Then i added my first Post:
@posts = Post.new(params[:post])
Here is when satan came and destroyed my vision. I just wanted to make a pretty list
of my Posts, I added following code:
@posts = Post.find(:all)
(For some reason my comments also will end up in this list?)
Now it's time to add a comment for that post, right.
@post = Post.find(params[:id])
That's for telling the comment to interact with the right Post-id, Im not sure if that's correct, anyway.
I now got another problem when I tried to add the comment data.
@comment = Comment.new(:post_if => post, :message => params[:message] (*See below)
*I think that params[:message] (it's supposed to pickup my text i entered in the "message"-textbox) is wrong, because if i do:
:message => "add text manual"
it works a little better but even now i sometimes get a string with this:
"!MAP-error, etc, etc, etc *add text manual*". So it's not very pretty.
Im not really sure what im asking for here, it's just that i thought i've read enough to complete a simple thing like this but i guess i was wrong.
Maybe someone can give me a hint or maybe im just not meant to work with rails!
PS - Sorry for the long post.
Have a great day!