I''m trying to get link_to_remote to assign a CSS class to the link it generates. My code is as follows: <%link_to_remote "Show Full Info", :update => "fullcontact" + reparray.last.to_s, :url => "/cm/full_contact/" + reparray.last.to_s, :classname => "contactlink" %> Which produces this HTML: <a href="#" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;">Show Full Info</a> And I would like it to produce this HTML: <a href="#" class="contactlink" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;">Show Full Info</a> I''ve also tried the code this way: <%link_to_remote "Show Full Info", { :update => "fullcontact" + reparray.last.to_s, :url => "/cm/full_contact/" + reparray.last.to_s}, { :classname => "contactlink" } %> (The only difference is the addition of the {}''s.) The result is the same. What am I doing wrong here? I don''t want to statically write the HTML into the view, which would work fine, but just isn''t as elegant as Ruby on Rails should be. Thanks, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/079e184f/attachment.html
If you go to the API page, http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M 000412, you''ll see that the signature for link_to_remote is link_to_remote(name, options = {}, html_options = {}) So, the secong argument is an options hash, and the last is the html_options hash - html_options is where you''d set the class. Your code should look like link_to_remote "Show Full Info", { :update => "fullcontact" + reparray.last.to_s, :url => "/cm/full_contact/" + reparray.last.to_s}, {}, { :class => "contactlink" } Also notice that it''s :class, not :classname. Hope this helps! Daniel _____ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of David R. Sent: Wednesday, June 28, 2006 8:58 AM To: rails@lists.rubyonrails.org Subject: [Rails] Assign CSS class to Link to Remote I''m trying to get link_to_remote to assign a CSS class to the link it generates. My code is as follows: <%link_to_remote "Show Full Info", :update => "fullcontact" + reparray.last.to_s , :url => "/cm/full_contact/" + reparray.last.to_s, :classname => "contactlink" %> Which produces this HTML: <a href="#" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;">Show Full Info</a>And I would like it to produce this HTML: <a href="#" class="contactlink" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;">Show Full Info</a>I''ve also tried the code this way: <%link_to_remote "Show Full Info", { :update => "fullcontact" + reparray.last.to_s, :url => "/cm/full_contact/" + reparray.last.to_s}, { :classname => "contactlink" } %> (The only difference is the addition of the {}''s.) The result is the same. What am I doing wrong here? I don''t want to statically write the HTML into the view, which would work fine, but just isn''t as elegant as Ruby on Rails should be. Thanks, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/52b02f7f/attachment-0001.html
Thanks for the help, Daniel. The code you provided produced an error, (wrong number of arguments, 4 for 3), but it was your explanation that helped me the most. The correct code to do what I was looking for was actually: <%link_to_remote "Show Full Info", { :update => "fullcontact" + reparray.last.to_s, :url => "/cm/full_contact/" + reparray.last.to_s}, { :class => "contactlink" } %> The empty hash you had in the middle of the code was causing the error. Thanks for the help, again, Daniel, and I hope this helps anybody else who has this problem! - David On 6/28/06, Daniel Higginbotham <daniel@flyingmachinestudios.com> wrote:> > If you go to the API page, > http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000412, > you''ll see that the signature for link_to_remote is > > *link_to_remote*(name, options = {}, html_options = {}) > > > > So, the secong argument is an options hash, and the last is the > html_options hash ? html_options is where you''d set the class. Your code > should look like > > > > link_to_remote "Show Full Info", > { :update => "fullcontact" + reparray.last.to_s, > :url => "/cm/full_contact/" + reparray.last.to_s}, > > {}, > { :class => "contactlink" } > > > > Also notice that it''s :class, not :classname. > > > > Hope this helps! > > > > Daniel > ------------------------------ > > *From:* rails-bounces@lists.rubyonrails.org [mailto: > rails-bounces@lists.rubyonrails.org] *On Behalf Of *David R. > *Sent:* Wednesday, June 28, 2006 8:58 AM > *To:* rails@lists.rubyonrails.org > *Subject:* [Rails] Assign CSS class to Link to Remote > > > > I''m trying to get link_to_remote to assign a CSS class to the link it > generates. My code is as follows: > > <%> link_to_remote "Show Full Info", > :update => "fullcontact" + reparray.last.to_s , > :url => "/cm/full_contact/" + reparray.last.to_s, > :classname => "contactlink" > %> > > Which produces this HTML: > > > <a > > href="#" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;" > > >Show Full Info</a> > > And I would like it to produce this HTML: > > > <a > > href="#" class="contactlink" onclick="new Ajax.Updater(''fullcontact7'', ''/cm/full_contact/7'', {asynchronous:true, evalScripts:true}); return false;" > > >Show Full Info</a> > > > I''ve also tried the code this way: > > <%> link_to_remote "Show Full Info", > { :update => "fullcontact" + reparray.last.to_s, > :url => "/cm/full_contact/" + reparray.last.to_s}, > { :classname => "contactlink" } > %> > > (The only difference is the addition of the {}''s.) The result is the > same. What am I doing wrong here? I don''t want to statically write the > HTML into the view, which would work fine, but just isn''t as elegant as Ruby > on Rails should be. > > Thanks, > David > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060628/68bb04d2/attachment.html