Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to render results collection #28

Open
bradseefeld opened this issue May 12, 2011 · 5 comments
Open

Unable to render results collection #28

bradseefeld opened this issue May 12, 2011 · 5 comments

Comments

@bradseefeld
Copy link

In the controller
@foos = Foo.find(:all)

In the view
<%= render @foos %>

Generates:
undefined method `model_name' for SimpleRecord::ResultsArray:Class

@treeder
Copy link
Member

treeder commented May 12, 2011

Shouldn't you be looping through @foos and printing each one? What output do
you expect from that?

On Thu, May 12, 2011 at 9:14 AM, bradseefeld <
[email protected]>wrote:

In the controller

@foos = Foo.find(:all)

In the view

<%= render @foos %>

Generates:
undefined method `model_name' for SimpleRecord::ResultsArray:Class

Reply to this email directly or view it on GitHub:
#28

@bradseefeld
Copy link
Author

See section 3.4.5 Rendering Collections @ http://guides.rubyonrails.org/layouts_and_rendering.html

The above syntax lets me define a partial named _foo.html.erb. That template is rendered for each item in the @foos collection. It is equivalent to doing:

<% @foos.each do |foo| -%>
<% render :partial => "foo", :locals => {:foo => foo} %>
<% end -%>

The long version works because there really isnt any rails magic going on (no need to know the model name). The desired version is more compact and typically the more accepted way when iterating through a collection of models.

@treeder
Copy link
Member

treeder commented May 12, 2011

Got it, feel like fixing it? ;) Seems like it would be simple enough, add
model_name to ResultsArray.

On Thu, May 12, 2011 at 1:08 PM, bradseefeld <
[email protected]>wrote:

See section 3.4.5 Rendering Collections @
http://guides.rubyonrails.org/layouts_and_rendering.html

The above syntax lets me define a partial named _foo.html.erb. That
template is rendered for each item in the @foos collection. It is equivalent
to doing:

<% @foos.each do |foo| -%>
<% render :partial => "foo", :locals => {:foo => foo} %>
<% end -%>

The long version works because there really isnt any rails magic going on
(no need to know the model name). The desired version is more compact and
typically the more accepted way when iterating through a collection of
models.

Reply to this email directly or view it on GitHub:
#28 (comment)

@bradseefeld
Copy link
Author

Oh, is that really it? Sorry, still fairly new to Ruby/Rails. I will give it a shot. Do i just fork, patch and send a pull request?

@treeder
Copy link
Member

treeder commented May 12, 2011

yep, exactly.

after you patch, you can install it locally on your machine to test it by
running "rake install".

On Thu, May 12, 2011 at 1:29 PM, bradseefeld <
[email protected]>wrote:

Oh, is that really it? Sorry, still fairly new to Ruby/Rails. I will give
it a shot. Do i just fork, patch and send a pull request?

Reply to this email directly or view it on GitHub:
#28 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants