I have this in a view:
<td id="action_<%= action.id %>">
<%= render :partial => "new", :locals => { :game =>
@game, :action => action, :count => count } %>
</td>
<% elsif action.hit %>
<td id="action_<%= action.id %>">
<%= render :partial => "hit", :locals => { :game =>
@game, :action => action, :count => count } %>
</td>
This in _new.html.erb
<%= link_to_remote "hit", :url => { :action =>
"add_hit", :id =>
action.id, :player => @game.players[count] }, :update =>
"action_#{action.id}" %> <%= link_to_remote "skip",
:url => { :action
=> "add_skip", :id => action.id, :player =>
@game.players[count] }, :update => "action_#{action.id}" %>
This in partial _hit.html.erb
<%= link_to_remote "(hit)", :url => { :action =>
"remove_hit", :id =>
action.id, :game => @game, :count => count, :player =>
@game.players[count] }, :update => "action_#{action.id}" %>
This in _skip.html.erb
<%= link_to_remote "(skip)", :url => { :action =>
"remove_skip", :id
=> action.id, :game => @game, :count => count, :player =>
@game.players[count] }, :update => "action_#{action.id}" %>
This in my controller
def add_hit
@action = Action.find(params[:id])
Player.find(params[:player]).actions << @action
@action.add_hit
render :partial => "hit", :locals => { :game =>
Game.find(params[:game].id), :action => @action, :count =>
params[:count] }
end
def remove_hit
@action = Action.find(params[:id])
@action.remove_hit
render :partial => "new", :locals => { :game =>
Game.find(params[:game].id), :action => @action, :count =>
params[:count] }
end
and ditto for skips
Yet I''m still getting nil errors all over the place. Have I not passed
the locals correctly? What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 17 Apr 2008, at 21:12, edberner wrote:> > and ditto for skips > > Yet I''m still getting nil errors all over the place. Have I not passed > the locals correctly? What am I doing wrong?Well it''s almost impossible to say for sure, because you haven''t told us where the error occurs, but for example in _hit.html.erb you''re using @game, but in add_hit you don''t seem to have defined @game (did you mean to just write game ?). The same is true for the remove_hit action and _new.html.erb Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s the error when I click from "hit" from the view
Here''s what it passes (/games/remove_hit/153?
count=2&game=7&player=9)
def add_hit
@action = Action.find(params[:id])
@game = Game.find(params[:game]) #looks like it can''t find game
Player.find(params[:player]).actions << @action
@action.add_hit
render :partial => "hit", :locals => { :game => @game,
:action =>
@action, :count => params[:count] }
end
activerecord::recordnotfound in gamescontroller#add_hit
couldn''t find game without an id
rails_root: /users/ellis/desktop/mlp
On Apr 17, 4:23 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 17 Apr 2008, at 21:12, edberner wrote:
>
> > and ditto for skips
>
> > Yet I''m still getting nil errors all over the place. Have I
not passed
> > the locals correctly? What am I doing wrong?
>
> Well it''s almost impossible to say for sure, because you
haven''t told
> us where the error occurs, but for example in _hit.html.erb you''re
> using @game, but in add_hit you don''t seem to have defined @game
(did
> you mean to just write game ?). The same is true for the remove_hit
> action and _new.html.erb
>
> Fred
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Like I said before you seem to be using @game without having set it. Fred On Apr 17, 9:37 pm, edberner <eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s the error when I click from "hit" from the view > Here''s what it passes (/games/remove_hit/153? > count=2&game=7&player=9) > def add_hit > @action = Action.find(params[:id]) > @game = Game.find(params[:game]) #looks like it can''t find game > Player.find(params[:player]).actions << @action > @action.add_hit > > render :partial => "hit", :locals => { :game => @game, :action => > @action, :count => params[:count] } > end > > activerecord::recordnotfound in gamescontroller#add_hit > couldn''t find game without an id > rails_root: /users/ellis/desktop/mlp > > On Apr 17, 4:23 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 17 Apr 2008, at 21:12, edberner wrote: > > > > and ditto for skips > > > > Yet I''m still getting nil errors all over the place. Have I not passed > > > the locals correctly? What am I doing wrong? > > > Well it''s almost impossible to say for sure, because you haven''t told > > us where the error occurs, but for example in _hit.html.erb you''re > > using @game, but in add_hit you don''t seem to have defined @game (did > > you mean to just write game ?). The same is true for the remove_hit > > action and _new.html.erb > > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I believe that Fred is right about the source of your problem.
A few other comments that might help:
1. If you''re going to pass @game into the partial as a local then
you should refer to it as game, not @game.
2. If you''re using rails 2.x, then use dom_id(@action) for the td
declaration: <td id="<%= dom_id_action %>">
3. Since the params appear to be the same, you could simplify your
code a lot by calculating the name of the partial and then calling
render :partial once.
4. Combine it all into something like this (note -- dom_id is used
by content_tag_for):
(controller)
@partial_name = case
when action.hit
''hit''
when action.miss
''miss''
else
''new''
(view)
content_tag_for :td, @action, render(:partial=>
@partial_name, :locals=>{:game =>
@game, :action => action, :count => count })
On Apr 18, 3:43 am, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Like I said before you seem to be using @game without having set it.
>
> Fred
>
> On Apr 17, 9:37 pm, edberner
<eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Here''s the error when I click from "hit" from the
view
> > Here''s what it passes (/games/remove_hit/153?
> > count=2&game=7&player=9)
> > def add_hit
> > @action = Action.find(params[:id])
> > @game = Game.find(params[:game]) #looks like it can''t find
game
> > Player.find(params[:player]).actions << @action
> > @action.add_hit
>
> > render :partial => "hit", :locals => { :game =>
@game, :action =>
> > @action, :count => params[:count] }
> > end
>
> > activerecord::recordnotfound in gamescontroller#add_hit
> > couldn''t find game without an id
> > rails_root: /users/ellis/desktop/mlp
>
> > On Apr 17, 4:23 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > wrote:
>
> > > On 17 Apr 2008, at 21:12, edberner wrote:
>
> > > > and ditto for skips
>
> > > > Yet I''m still getting nil errors all over the
place. Have I not passed
> > > > the locals correctly? What am I doing wrong?
>
> > > Well it''s almost impossible to say for sure, because you
haven''t told
> > > us where the error occurs, but for example in _hit.html.erb
you''re
> > > using @game, but in add_hit you don''t seem to have
defined @game (did
> > > you mean to just write game ?). The same is true for the
remove_hit
> > > action and _new.html.erb
>
> > > Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks that helped a lot. I got it now. On Apr 18, 9:14 am, AndyV <AndyVana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I believe that Fred is right about the source of your problem. > > A few other comments that might help: > 1. If you''re going to pass @game into the partial as a local then > you should refer to it as game, not @game. > 2. If you''re using rails 2.x, then use dom_id(@action) for the td > declaration: <td id="<%= dom_id_action %>"> > 3. Since the params appear to be the same, you could simplify your > code a lot by calculating the name of the partial and then calling > render :partial once. > 4. Combine it all into something like this (note -- dom_id is used > by content_tag_for): > > (controller) > @partial_name = case > when action.hit > ''hit'' > when action.miss > ''miss'' > else > ''new'' > > (view) > content_tag_for :td, @action, render(:partial=> > @partial_name, :locals=>{:game => > @game, :action => action, :count => count }) > > On Apr 18, 3:43 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Like I said before you seem to be using @game without having set it. > > > Fred > > > On Apr 17, 9:37 pm, edberner <eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Here''s the error when I click from "hit" from the view > > > Here''s what it passes (/games/remove_hit/153? > > > count=2&game=7&player=9) > > > def add_hit > > > @action = Action.find(params[:id]) > > > @game = Game.find(params[:game]) #looks like it can''t find game > > > Player.find(params[:player]).actions << @action > > > @action.add_hit > > > > render :partial => "hit", :locals => { :game => @game, :action => > > > @action, :count => params[:count] } > > > end > > > > activerecord::recordnotfound in gamescontroller#add_hit > > > couldn''t find game without an id > > > rails_root: /users/ellis/desktop/mlp > > > > On Apr 17, 4:23 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On 17 Apr 2008, at 21:12, edberner wrote: > > > > > > and ditto for skips > > > > > > Yet I''m still getting nil errors all over the place. Have I not passed > > > > > the locals correctly? What am I doing wrong? > > > > > Well it''s almost impossible to say for sure, because you haven''t told > > > > us where the error occurs, but for example in _hit.html.erb you''re > > > > using @game, but in add_hit you don''t seem to have defined @game (did > > > > you mean to just write game ?). The same is true for the remove_hit > > > > action and _new.html.erb > > > > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---