computer_smile
computer_smile

Reputation: 2227

Simple link to bootstrap modal confusion rails

I don't understand what is wrong with my syntax here, maybe I need another pair of eyes this should result in a user clicking on the twitter image to pop open a bootstrap modal, but I'm getting this error-

wrong number of arguments (3 for 2)

The rails link_to with image_tag-

<li><%= link_to image_tag "/assets/twitter.png", "#myModal", :data => { :toggle =>"modal" } %></li>

modal for html

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Hey!</h3>
  </div>
  <div class="modal-body">
    <p>6 modals?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  </div>
</div>

What am I overlooking here? Thanks for your attention and for taking a look.

Upvotes: 0

Views: 637

Answers (1)

Josh Rieken
Josh Rieken

Reputation: 2266

You'll need parentheses around the image_tag argument, like so:

<li><%= link_to image_tag("/assets/twitter.png"), "#myModal", :data => { :toggle =>"modal" } %></li>

Without the parentheses, Ruby thinks you're passing all the arguments into image_tag, just like this:

<li><%= link_to image_tag("/assets/twitter.png", "#myModal", :data => { :toggle =>"modal" }) %></li>

Some consider it good style to wrap all arguments in parens to avoid cases like this, while others prefer the more clean look of as few parens as possible.

Upvotes: 1

Related Questions