Peter Barry
2005-Oct-28 10:25 UTC
Actionless self-referential views , logic in my views, yes, but less LOC. One draw back, it dont work.
<%= render (:partial => "collapsed_blog" , :locals => {:be => be , :hide => "yes"}) %> This above code is in a .rhtml page. Here is the partial it renders: <p class=<%="blog_content" + be.id.to_s%>> <% if hide == "yes" %> <%= be.blogshorttext %> <%= link_to_remote ('' [See Full Text ('' + be.wordcount + '')]'', :update=> ("blog_content" + be.id.to_s), :url=> {:partial => ''collapsed_blog'' ,:id =>be.id}, :locals =>{:hide => "no"})%> <% else %> <%= be.blog_text %> <%= link_to_remote ('' [Collapse]'', :update=> ("blog_content" + be.id.to_s), :url=> {:partial => ''collapsed_blog'' , :id =>be.id}, :locals =>{:hide => "yes"})%> <%end%> </p> You should notice that both link_to_remotes are attempting self-reference. Which is not working. When the link is clicked it should toggle the condition hide, I dont know if it is the framework forbidding this or if my link_to_remote is malformed or another form should be used. I refactored to this code because I didnt like having two actions for hide and show, I felt I didnt need that. Instead I thought once the partial is rendered it can submit to itself (see above link_to_remote). I tried having the locals params inside the :url => and also as above outside. Truth is my understanding of the parameters to link_to_remote is iffy, because I cant find one that excepts locals even though I am sure they must exist. The intial call from the parent correctly renders the partial but if I click the link [See full text] nothing changes , I am assuming that the local param is not being passed or set correctly. I want to know what are your thoughts , should I be using an action here even though it requires more code, or is there a solution to fix my above implementation without changing back to action based rendering for this particular functionality?
David Chilton
2005-Oct-28 15:40 UTC
RE: Actionless self-referential views , logic in my views, yes, but less LOC. One draw back, it dont work.
You can''t reference partials like that, it only works on render. View source on the page and see what come up, I bet it won''t be what you''re expecting. I''d use a route to interpret an addition argument for hide to pass to the action like: map.connect.blog = ''/blog_controller/collapse_blog/:id/:hide'' Look at the routing wiki for more on defaulting the :hide parameter and limiting it to a yes or no David> -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails- > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Peter Barry > Sent: Friday, October 28, 2005 6:25 AM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] Actionless self-referential views , logic in myviews,> yes, but less LOC. One draw back, it dont work. > > <%= render (:partial => "collapsed_blog" , :locals => {:be => be , > :hide => "yes"}) %> > > This above code is in a .rhtml page. > > Here is the partial it renders: > > <p class=<%="blog_content" + be.id.to_s%>> > > <% if hide == "yes" %> > <%= be.blogshorttext %> > <%= link_to_remote ('' [See Full Text ('' + be.wordcount + '')]'', > :update=> ("blog_content" + be.id.to_s), > :url=> {:partial => ''collapsed_blog'' ,:id =>be.id}, > :locals =>{:hide => "no"})%> > > <% else %> > <%= be.blog_text %> > <%= link_to_remote ('' [Collapse]'', > :update=> ("blog_content" + be.id.to_s), > :url=> {:partial => ''collapsed_blog'' , :id =>be.id}, > :locals =>{:hide => "yes"})%> > > <%end%> > </p> > > You should notice that both link_to_remotes are attempting > self-reference. Which is not working. When the link is clicked it > should toggle the condition hide, I dont know if it is the framework > forbidding this or if my link_to_remote is malformed or another form > should be used. > > I refactored to this code because I didnt like having two actions for > hide and show, I felt I didnt need that. Instead I thought once the > partial is rendered it can submit to itself (see above > link_to_remote). I tried having the locals params inside the :url => > and also as above outside. Truth is my understanding of the parameters > to link_to_remote is iffy, because I cant find one that excepts locals > even though I am sure they must exist. > > The intial call from the parent correctly renders the partial but if > I click the link [See full text] nothing changes , I am assuming that > the local param is not being passed or set correctly. I want to know > what are your thoughts , should I be using an action here even though > it requires more code, or is there a solution to fix my above > implementation without changing back to action based rendering for > this particular functionality? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails==============================================================================CONFIDENTIALITY NOTICE: The information in this electronic message (including any attachments) is confidential and may be privileged or proprietary. If you are not the intended recipient, any dissemination, disclosure, copying, downloading, or other use of the information is prohibited and unauthorized, and may be unlawful, regardless of address or routing. If you are not the intended recipient, please inform the sender immediately and permanently delete and destroy the original and any copies of this message, including any attachments. ==============================================================================