On Jan 29, 2013, at 1:58 PM, Ryo Saeba wrote:
> I tried Walters suggestion and put my display-table in a partial; this
> is what the method looked like
>
> def index
> if(params[:q])
> @games = Game.search(params[:search])
> else
> render :partial => 'search_results'
> end
> end
>
> But it would cause me a NoMethod Error... it says that the "each"
> function was not defined, but why?
I think you have it backwards. If there's no query, there's nothing to put in the partial, but the partial is needed in the case that you DO have a search query. Make a second partial that only has "No search yet" in it. Put that in the else side. In the if side, put this:
render :partial => 'search_results', :locals => @games
Inside your partial, change any instance of @games to games (remove the @).
There's an even easier way to do this, and that's by making a single row of your table as a partial, and saving it with the name _game.html.erb. Then in your index page, add this:
<table>
<%= render @games %>
</table>
If you haven't done so yet, I really recommend a thorough read of the Rails Guide on Views and Rendering. http://guides.rubyonrails.org
Walter
>
> Rolando Garros suggestion is simply not changing anything, maybe I'm not
> implementing it correctly...
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment