Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

Trouble with relationships

I'm having an issue with the relationship between my user model (which I call writers) and my status model (which I call articles).

Currently the drop down to select a writer for the article has "#<Writer:0x4658a78>" Also when I try to display the first name of the writer I get a nil reference error.

There seems to be some issue with my writer model, but I'm not sure what it may be.

Also I'm using the current versions of all of the software, which has had plenty of issues... So I'm guessing this is also related to that.

2 Answers

Artem Prytkov
Artem Prytkov
11,932 Points

What version of Rails you use?

It looks like you pass writer instance insted of his name, make sure to check if you set ralations for models and set pemissions.

I'm using Rails 4.1.1

I tweaked some of the code in the controller for my article and set it's writer to the current_writer through devise.

Edit: And yes, at that time I was only displaying the writer, not the name of the writer. Because the writer contained in my article was not referencing the correct writer.

My code is working now, just maybe not the best way to do it.

in article controller:

def create @article = Article.new(article_params) @article.writer = current_writer @article.save ...