.erb question

22 views
Skip to first unread message

Dave Castellano

unread,
Oct 19, 2013, 5:15:11 PM10/19/13
to rubyonra...@googlegroups.com
Hi,

I need to use a variable set in erb to give an element an ID...

For example:

In view...

<% n = 1 %>

then

<span id= "<% n %>" ><%= picture.title %></span>


...can't figure out how to set the ID of the span element above.

Any help would be appreciated

Dave

--
Posted via http://www.ruby-forum.com/.

tiredpixel

unread,
Oct 19, 2013, 5:55:44 PM10/19/13
to rubyonra...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In ERB, `<%` denotes code, the 'result' of which doesn't get inserted,
and `<%=` denotes code, the 'result' of which does get inserted. Thus,
I expect you're finding that the `picture.title` gets inserted, but
the `n` doesn't. Try changing the line to something like:

<span id= "<%= n %>" ><%= picture.title %></span>

Peace,
tiredpixel


On 19/10/2013 22:15, Dave Castellano wrote:
> Hi,
>
> I need to use a variable set in erb to give an element an ID...
>
> For example:
>
> In view...
>
> <% n = 1 %>
>
> then
>
> <span id= "<% n %>" ><%= picture.title %></span>
>
>
> ...can't figure out how to set the ID of the span element above.
>
> Any help would be appreciated
>
> Dave
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSYv/gAAoJEOFolTkanF7V+tgIAIZnBNq7YSVviwSsmG0rG0Ty
d1uCRHJ7zmkoI3a6wMe8jIFGcrJHZKLCnhuP61PN1J8JKbOfl3TR544jy0YDV+N0
wUz2+wOw8JEF/oqBBVOb2eiwB4A8HsshkTb2P9n+yLkXDVp+OdhJzqDX/yROJvUp
GdQw8Ihnoje88F9UVVRzDjsaxF7MO25fhGaC2od9Q8a6eun6fOGHTApncyTim8Sd
OeSW7Ez9Ucbr1bUK5AzVdTZwDcdrjfOpdaGxChS5WNpMQAZAQt2buYw9g4z+zCaq
8jsANN71pGCqZDlW2JV8Ary143WKhN6eSm0nNxOISs33pN81FdLCmlFJ2EPfbu0=
=YOpg
-----END PGP SIGNATURE-----

Walter Lee Davis

unread,
Oct 20, 2013, 7:12:29 PM10/20/13
to rubyonra...@googlegroups.com
And, of course you know this, the first character of an ID cannot be numeric in HTML. (It must begin with an alpha character or an underscore.)

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5262FFE0.1080802%40tiredpixel.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages