Stupid question. I'm in deadend

A

Artyom None

I'm newbie. Please, help. I suppose it's easy :)
I have admin controller which is working ok and with usual controller I
have trouble.
This is app/controllers/team_controller.rb
____________________________________________
class TeamController < ApplicationController
def show
@team = Team.find(params[:id])
end
end
___________________________________________

And in app/controllers/admin/teams_controller.rb "Show" function is
absolutely same. Then, app/views/admin/teams/show.rhtml looks like
<% for column in Team.content_columns %>
<p>
<% if column.human_name != "Image" %>
<b><%= column.human_name %>:</b> <%=h @team.send(column.name) %>
<% else %>
<%= image_tag url_for_file_column :"team", :"image" %>
<% end %>
</p>
<% end %>
But when I try to use this code in app/views/team/show.rhtml I get an
error:
" Showing app/views/team/show.rhtml where line #6 raised:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.split"
 
P

Phlip

Artyom said:
I'm newbie. Please, help. I suppose it's easy :)

Two blanket suggestions:

- Ruby is not Rails. You need both a book on Rails
(there's no excuse not to have one), and you need
to post to the Google Group ruby-on-rails-talk

- you should learn unit tests first, and write them
for every function. Rails makes this super-easy,
and the tests help answer questions
I have admin controller which is working ok and with usual controller I
have trouble.
This is app/controllers/team_controller.rb
____________________________________________
class TeamController < ApplicationController
def show
@team = Team.find(params[:id])
end
end
___________________________________________

And in app/controllers/admin/teams_controller.rb "Show" function is
absolutely same.

Why do you have both team_controller and teams_controller? The convention is
team_controller, singular.
Then, app/views/admin/teams/show.rhtml looks like
<% for column in Team.content_columns %>

This is probably scaffold-generated code. If you don't actually need a full
scaffold, you could erase the entire contents of the .rhtml, and put in
only this:

<%= @team.inspect %>

That would show what's really going on in your variable. It might be nil,
and .inspect will show that without crashing.

Next, you must hit your page with some URI like /teams/show/1, where 1 is
the id of a team record that really exists, typically in the 'development'
database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top