Hi, I''m pretty sure this is a simple problem but I can''t seem
to work it
out.
I have a series of news stories and I would like the body of the story
to be displayed (using a visual_effect toggle) when the user clicks on
the title.
The toggle works ok, but it does not matter which title I click on, only
the first story is ever displayed.
Can anyone see what is the problem?
Thanks
<h2>Latest News</h2>
<% for newsitem in @newsitems %>
<div class="item">
<h2><%= link_to newsitem.title, "#", :onclick =>
visual_effect(:toggle_appear, (''newsitem.id''), :duration =>
0.5) %>
</h2>
<div id="<%= (''newsitem.id'') %>"
style="display:none">
<h6><%= newsitem.created_at.strftime(''%a %d %b %Y,
%I:%M%p'') %> by <%newsitem.user.login %></h6>
<p><%= newsitem.body %></p>
</div>
</div>
<% end %>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Aug 26, 9:06 pm, Dan Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, I''m pretty sure this is a simple problem but I can''t seem to work it > out. > I have a series of news stories and I would like the body of the story > to be displayed (using a visual_effect toggle) when the user clicks on > the title. > > The toggle works ok, but it does not matter which title I click on, only > the first story is ever displayed.Your problem (which you should be able to see if you looked at the html) is that all of your divs have as id the string newsitem.id. When you write (''newsitem.id'') (not sure what you were trying to accomplish with the parentheses no interpolation is taking place, that''s just a string literal. if you want interpolation then you need to use double quotes and #{} to indicate what should be interpolated, eg "my name is #{ name } " Fred> > Can anyone see what is the problem? > Thanks > > <h2>Latest News</h2> > <% for newsitem in @newsitems %> > <div class="item"> > <h2><%= link_to newsitem.title, "#", :onclick => > visual_effect(:toggle_appear, (''newsitem.id''), :duration => 0.5) %> > </h2> > > <div id="<%= (''newsitem.id'') %>" style="display:none"> > <h6><%= newsitem.created_at.strftime(''%a %d %b %Y, %I:%M%p'') %> by <%> newsitem.user.login %></h6> > > <p><%= newsitem.body %></p> > </div> > </div> > <% end %> > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try replacing
visual_effect(:toggle_appear, (''newsitem.id''), :duration =>
0.5) with
visual_effect(:toggle_appear, "#{newsitem.id}", :duration => 0.5)
and
<div id="<%= (''newsitem.id'') %>"
style="display:none"> with
<div id="<%= newsitem.id %>"
style="display:none">
The way you have it is the literal string ''newsitem.id''.
"#{newsitem.id}" and <%= newsitem.id %> should resolve to what
you
want, the id of the item.
On Aug 26, 2:06 pm, Dan Smith
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi, I''m pretty sure this is a simple problem but I can''t
seem to work it
> out.
> I have a series of news stories and I would like the body of the story
> to be displayed (using a visual_effect toggle) when the user clicks on
> the title.
>
> The toggle works ok, but it does not matter which title I click on, only
> the first story is ever displayed.
>
> Can anyone see what is the problem?
> Thanks
>
> <h2>Latest News</h2>
> <% for newsitem in @newsitems %>
> <div class="item">
> <h2><%= link_to newsitem.title, "#", :onclick
=>
> visual_effect(:toggle_appear, (''newsitem.id''), :duration
=> 0.5) %>
> </h2>
>
> <div id="<%= (''newsitem.id'') %>"
style="display:none">
> <h6><%= newsitem.created_at.strftime(''%a %d %b %Y,
%I:%M%p'') %> by <%> newsitem.user.login %></h6>
>
> <p><%= newsitem.body %></p>
> </div>
> </div>
> <% end %>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---