1

I have a partial _album.html.erb and it has a variable "album" I have a collection @albums . For each in the collection I want to render the partial. But I don't use the option "collection:" because I want to put each one in different position. Here is my code:

<% @albums.each do | f | %>
     ..........
    <td>
           <%= render partial: "album", locals: {"album" f} %>
      .........
<% end %>

This code returns a SyntaxError. I don't know why this happens.

1
  • Actually it will be very helpful if you posted logs with Error Commented Jun 16, 2014 at 4:33

3 Answers 3

5

You haven't any divider between "album" and f, so try locals: {album: f} or :album => f

Sign up to request clarification or add additional context in comments.

7 Comments

I have a space there . It's my phone's problem. But Thanks
You can't use space, it's a hash. Use => or : ad I suggest.
Sorry, I misunderstand you. I have ":" Between album and f . And have a space between : and f.
Ok, got it. Perhaps then, in partial are you using @album? Cause this location variable will be just album. Use this name instead, and return it in other calls as local.
I use it as album.title. So it just local variable not instance variable .
|
1

Locals

Further to zishe's correct answer, you'll need to look up on how to set the syntax for partial local variables:

<%= render partial: "form", locals: {zone: @zone} %>

Rails basically sends a hash of key: value pairs, which means the syntax has to be like this:

locals: {key: value, "key" => value}

You have to remember Rails is basically just a collection of files & classes, which means anything you do has to conform to the ways in which Ruby allows you to assign & pass data, a hash being one of the main ways

Comments

1

I had this problem and I tried with locals: {..} but it didn't work.

You can try this that worked for me:

 <%= render partial: "form", zone: @zone %>

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.