William Hatch
2010-Sep-09 14:55 UTC
Syntax with link_to using block, remote, parameters and class/id
Rails 3rc, Ruby 1.9.2 Newish to rails; very new to rails3 I''m trying to create a link using a block so I can wrap the name contents in a span, for an ajax request using multiple parameters and finally, also specifying the class and id of the generated link element. Here''s what I''ve got so far: <%= link_to( :url=>{ :controller => ''themes'', :action => ''remove_tag'', :entity_id => entity_id, :theme_id => theme_id, :entity => entity, :element_id => element_id, :parent_id=>parent_id }, :remote => true, :id => "theme-tag-#{entity}-#{entity_id}", :class => "tag") do %> <span class=''subtract''><%= tag %></span> <% end %> This generates the following: <a href="/explore/index/theme-tag-user-3?url[controller]=themes&url[action]=remove_tag&url[entity_id]=3&url[theme_id]=16&url[entity]=user&url[element_id]=filter-contributor-3&url[parent_id]=filter-contributors&remote=true&class=tag"><span class="subtract">Test Descriptor</span></a> So, the href isn''t correct, no class or id attributes as they''re being treated like parameters instead, and normally with :remote=>true, I''d expect to see data-remote=true in the element. Also, and this is just my desire to learn more about why... but a link_to without a block would be something like link_to "Link Name", {url_stuff...}, :remote=>true, :class="my-class", :id=>"1" and so on, and these all work, but why do I have to specify the :url=> when using the block, but not otherwise? It just seems there''s a significant syntactical difference between the two and I don''t understand why there would be and I''d like to. Thanks. Bill -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
radhames brito
2010-Sep-09 15:28 UTC
Re: Syntax with link_to using block, remote, parameters and class/id
change :url to url_for On Thu, Sep 9, 2010 at 10:55 AM, William Hatch <wkhatch-BUHhN+a2lJ4@public.gmane.org> wrote:> Rails 3rc, Ruby 1.9.2 > > Newish to rails; very new to rails3 > > I''m trying to create a link using a block so I can wrap the name contents > in a span, for an ajax request using multiple parameters and finally, also > specifying the class and id of the generated link element. Here''s what I''ve > got so far: > > <%= link_to( > :url=>{ > :controller => ''themes'', :action => ''remove_tag'', > :entity_id => entity_id, :theme_id => theme_id, > :entity => entity, :element_id => element_id, :parent_id=>parent_id > }, > :remote => true, > :id => "theme-tag-#{entity}-#{entity_id}", > :class => "tag") do %> > <span class=''subtract''><%= tag %></span> > <% end %> > > This generates the following: > > <a > href="/explore/index/theme-tag-user-3?url[controller]=themes&url[action]=remove_tag&url[entity_id]=3&url[theme_id]=16&url[entity]=user&url[element_id]=filter-contributor-3&url[parent_id]=filter-contributors&remote=true&class=tag"><span > class="subtract">Test Descriptor</span></a> > > So, the href isn''t correct, no class or id attributes as they''re being > treated like parameters instead, and normally with :remote=>true, I''d expect > to see data-remote=true in the element. Also, and this is just my desire to > learn more about why... but a link_to without a block would be something > like link_to "Link Name", {url_stuff...}, :remote=>true, :class="my-class", > :id=>"1" and so on, and these all work, but why do I have to specify the > :url=> when using the block, but not otherwise? It just seems there''s a > significant syntactical difference between the two and I don''t understand > why there would be and I''d like to. Thanks. > > > > Bill > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
William K. Hatch Jr.
2010-Sep-09 15:39 UTC
Re: Syntax with link_to using block, remote, parameters and class/id
On Sep 9, 2010, at 11:28 AM, radhames brito wrote:> change :url to url_forThanks, that did it. Man, that was most frustrating;-)> > On Thu, Sep 9, 2010 at 10:55 AM, William Hatch <wkhatch-BUHhN+a2lJ4@public.gmane.org> wrote: > Rails 3rc, Ruby 1.9.2 > > Newish to rails; very new to rails3 > > I''m trying to create a link using a block so I can wrap the name contents in a span, for an ajax request using multiple parameters and finally, also specifying the class and id of the generated link element. Here''s what I''ve got so far: > > <%= link_to( > :url=>{ > :controller => ''themes'', :action => ''remove_tag'', > :entity_id => entity_id, :theme_id => theme_id, > :entity => entity, :element_id => element_id, :parent_id=>parent_id > }, > :remote => true, > :id => "theme-tag-#{entity}-#{entity_id}", > :class => "tag") do %> > <span class=''subtract''><%= tag %></span> > <% end %> > > This generates the following: > > <a href="/explore/index/theme-tag-user-3?url[controller]=themes&url[action]=remove_tag&url[entity_id]=3&url[theme_id]=16&url[entity]=user&url[element_id]=filter-contributor-3&url[parent_id]=filter-contributors&remote=true&class=tag"><span class="subtract">Test Descriptor</span></a> > > So, the href isn''t correct, no class or id attributes as they''re being treated like parameters instead, and normally with :remote=>true, I''d expect to see data-remote=true in the element. Also, and this is just my desire to learn more about why... but a link_to without a block would be something like link_to "Link Name", {url_stuff...}, :remote=>true, :class="my-class", :id=>"1" and so on, and these all work, but why do I have to specify the :url=> when using the block, but not otherwise? It just seems there''s a significant syntactical difference between the two and I don''t understand why there would be and I''d like to. Thanks. > > > > Bill > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
radhames brito
2010-Sep-09 15:46 UTC
Re: Syntax with link_to using block, remote, parameters and class/id
yeah, you were passing a hash and not a helper method On Thu, Sep 9, 2010 at 11:39 AM, William K. Hatch Jr. < stompinwilly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Sep 9, 2010, at 11:28 AM, radhames brito wrote: > > > change :url to url_for > > Thanks, that did it. Man, that was most frustrating;-) > > > > On Thu, Sep 9, 2010 at 10:55 AM, William Hatch <wkhatch-BUHhN+a2lJ4@public.gmane.org> wrote: > > Rails 3rc, Ruby 1.9.2 > > > > Newish to rails; very new to rails3 > > > > I''m trying to create a link using a block so I can wrap the name contents > in a span, for an ajax request using multiple parameters and finally, also > specifying the class and id of the generated link element. Here''s what I''ve > got so far: > > > > <%= link_to( > > :url=>{ > > :controller => ''themes'', :action => ''remove_tag'', > > :entity_id => entity_id, :theme_id => theme_id, > > :entity => entity, :element_id => element_id, > :parent_id=>parent_id > > }, > > :remote => true, > > :id => "theme-tag-#{entity}-#{entity_id}", > > :class => "tag") do %> > > <span class=''subtract''><%= tag %></span> > > <% end %> > > > > This generates the following: > > > > <a > href="/explore/index/theme-tag-user-3?url[controller]=themes&url[action]=remove_tag&url[entity_id]=3&url[theme_id]=16&url[entity]=user&url[element_id]=filter-contributor-3&url[parent_id]=filter-contributors&remote=true&class=tag"><span > class="subtract">Test Descriptor</span></a> > > > > So, the href isn''t correct, no class or id attributes as they''re being > treated like parameters instead, and normally with :remote=>true, I''d expect > to see data-remote=true in the element. Also, and this is just my desire to > learn more about why... but a link_to without a block would be something > like link_to "Link Name", {url_stuff...}, :remote=>true, :class="my-class", > :id=>"1" and so on, and these all work, but why do I have to specify the > :url=> when using the block, but not otherwise? It just seems there''s a > significant syntactical difference between the two and I don''t understand > why there would be and I''d like to. Thanks. > > > > > > > > Bill > > > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.