0

So basically in my partial I have the following line of code

...
<%= " active" if current_user."#{prop_row}" == "repeat-x" %>
...

So I tried to pass in the following variables "prop_id", "prop_row" using:

<%= render :partial => "users/image_props/repeat", :prop_id => "mbr", :prop_row => "main_background_repeat" %>

I get the error

/Users/codyjames408/rails/moz/app/views/users/image_props/_repeat.html.erb:4: syntax error, unexpected tSTRING_BEG
...= ( " active" if current_user."#{prop_row}" == "repeat-x" );...
...     

                      ^

I think the errors because its appending a string instead of the row method. But I am pulling my hair trying to figure how to work around this.

I would love to turn this into a big helper method or something! I just don't know how...

1 Answer 1

2

If prop_row is a string, containing the name of an attribute, you ucan do this:

<%= " active" if current_user.attributes[prop_row] == "repeat-x" %>

Or use this:

<%= " active" if current_user.send(prop_row.to_sym) == "repeat-x" %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.