Passing variable to partial failure

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?

With regard to button_to, on first (and quick) inspection, I see that
you
are missing your first argument, name.

Your button_to:

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

I usually get an error message like this when I am missing arguments in
button_to.

The button_to prototype in Rails 4 is:
(button_to (ActionView::Helpers::UrlHelper) - APIdock)
button_to(name = nil, options = nil, html_options = nil, &block)

name is what appears on the button, usually string like “Delete”, “New”,
etc.

Next, I am assuming that blockrelationships_path is your url path,
controller/action/(:id)… something defined in your router?

I see that you are using a block in ‘do’? Doesn’t seem that you need it.
Do you have content for the block?

I would try first to rewrite your button_to as: (Not sure about brackets
surrounding your params)

<%= button_to (“Button Face Name String”, blockrelationships_path, {
class:
‘btn btn-default btn-xs’,
params: {
blocker_callsign: @callsign,
blocked_callsign: blockedcallsign
}, remote: true } ) %>

If you need the block then I would try rewrite:

<%= button_to [“Button Face Name String”, blockrelationships_path, {
class:
‘btn btn-default btn-xs’,
params: {
blocker_callsign: @callsign,
blocked_callsign: blockedcallsign
}, remote: true }] do %>

<% end %>

I do not offer this latter suggestion confidentially as I could find
very
little on-line documentation regarding the use/syntax for button_to with
a
block.

I am also concerned by:
<%= render partial: ‘shared/block’, locals: { blockedcallsign:
post.callsign } %> … It is apparent how you are using
blockedcallsign
in your ‘shared/block’ partial, are you sure that post.callsign is valid
always? Then I see @callsign? What is @callsign? Is it valid? Is it
related to post.callsign? Not sure about Rails 4, but in params have
two
keys with the same name, yet different values.

Hope this helps…

Liz

Sorry, I see now blocker vs blocked. So same key name observations is
wrong…

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
http://stackoverflow.com/questions/14986559/rails-undefined-method-stringify-keys),
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 %>

<% end %>

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

On 28 June 2015 at 15:15, Bazley [email protected] wrote:

            params: {

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

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

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.