RE: restricting list output (newbie)

Huh? :slight_smile: Oh you’re probably referring to scaffolding.

Well, you could just do it by hand.

Say your table looks like this:

Authors

id
first_name
last_name
email

Controller:

def list
@authors = Author.find(:all)
# or you might have paginate stuff there instead
end

View:

Just write this code by hand:

<% for author in @authors %> <% end %>
First Name Last Name
<%=author.first_name %> <%=author.last_name %>

Don’t fear the HTML :slight_smile:

i tried your solution, but it didn´t seem “clean” to me.

i thought of something like (referring to the example):
@authors = Author.find(‘first_name’,‘last_name’)

of course, this code is not correct. but there should be an easier way
than
modifying the HTML by hand, right?

patrick

patrick k wrote:

i tried your solution, but it didn´t seem “clean” to me.

i thought of something like (referring to the example):
@authors = Author.find(‘first_name’,‘last_name’)

of course, this code is not correct. but there should be an easier way than
modifying the HTML by hand, right?

No, generated HTML is just to get you started. You should expect to
replace it completely.

Justin

define a subset of Author.content_columns in your controller and then
use this in your scaffold loop instead of Author.content_columns
directly:

desired_columns = [‘first_name’, ‘last_name’]
@content_columns = Author.content_columns.select { |c|
desired_columns.include?(c.name) }

  • james

nice. tried it and … worked. thanks.

looks like this is a more appropriate way to handle the problem compared
with changing the HTML-code.

this should be part of the tuturial, wiki … (maybe it already is, but
i
didn´t find it).

Hi:

I am a newbie too so this answer may be junk. However, here goes…
(all the techno geniuses please be nice, I am attempting to be helpful).

@authors = Author.find(:select => 'first_name, last_name,etc) etc.

However, the other answer you were given is perfectly “clean” in my
opinion and certainly gives more control.

bruce