Passing variable to partial failure

33 views
Skip to first unread message

Bazley

unread,
Jun 27, 2015, 3:57:23 PM6/27/15
to rubyonra...@googlegroups.com
In the view.html.erb:

<%= render @posts %>

In each _post.html.erb:

<%= render partial: 'shared/block', locals: { blockedcallsign: post.callsign } %>

In each _block.html.erb:

<%= button_to blockrelationships_path, class: 'btn btn-default btn-xs',
                        
params: { 
                            blocker_callsign
: @callsign, 
                            blocked_callsign
: blockedcallsign
                        
},
                        remote
: true do %>
<% end %>

I get the error: `undefined local variable or method 'blockedcallsign'`. What's wrong with the code?
Message has been deleted
Message has been deleted

Bazley

unread,
Jun 28, 2015, 10:15:32 AM6/28/15
to rubyonra...@googlegroups.com
Thank you very much for your help.
Sorry, I should have included what's inside the block: it's a glyphicon block sign. 
I've researched the correct format for including a block (example here), and I think I have it correct below (it works when I use a string such as 'baz'). But when I use blockedcallsign, it still gives the error undefined local variable or method `blockedcallsign'.
The full code is below:

<%= button_to blockrelationships_path(
               
params: {
                  blocker_callsign
: @character.callsign,
                  blocked_callsign
: blockedcallsign, #'baz'
                  viewed_callsign
:  @view_character.callsign
               
},
                remote
: true
             
),
             
class: 'btn btn-default btn-xs' do %>
 
<span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span>
<% end %>

I am completely at a loss. Is it perhaps something to do with calling a partial inside a partial?

Colin Law

unread,
Jun 28, 2015, 12:24:24 PM6/28/15
to rubyonra...@googlegroups.com
I have had that sort of issue occasionally caused by a non-printable
character which has somehow got inserted into the source, try
re-typing the line where the parameter is passed and where it used to
eliminate that possibility.

If not that does it help if you call it with a string, blockedcallsign: "text"

Also try using the variable in the partial just as a string rather
than inside the button_to function, to prove it is not to do with the
context where you are using it.

As a final test try changing the parameter name. Not sure why it
should help but if nothing else it might give you a clue

Colin

Bazley

unread,
Jun 28, 2015, 5:07:30 PM6/28/15
to rubyonra...@googlegroups.com
Thank you all very much. I'm afraid the problem was me, being a moron. There's nothing wrong with the code. There was a second forgotten 'render' in view.html.erb causing the problem. Sorry. Thank you once again.
Reply all
Reply to author
Forward
0 new messages