I''d like my print link to look like a button. Its action responds to
a GET request (as I think it should.) I wrote this helper:
<code>
def button_link( label, path, *features ) # makes a link look like a
button
linktext = "<input type=button value=''" << label
<< "'' onClick=\""
if features.length > 0 # opens new window, assigns features
linktext << "window.open(''" << path
<< "'',''" << label <<
"''"
features.each { |feature| linktext << ",''"
<< feature << "''" }
linktext << '');return false;">''
else # opens in same window
linktext << "self.location=''" << path
<< ''\''">''
end
end
</code>
Which works as expected in the view, e.g.
<code>
<%= button_link( ''Print'', url_for( ... ),
''new_window'' ) %>
</code>
But feels kind of hacky. Does anyone have a more elegant solution?
TIA,
Craig
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Mar-02 15:31 UTC
Re: More elegant solution for turning link into button?
On Tue, Mar 2, 2010 at 7:26 AM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like my print link to look like a button. Its action responds to > a GET request (as I think it should.) I wrote this helper:> But feels kind of hacky. Does anyone have a more elegant solution?Just style a regular link; that''s what CSS is for... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
> Just style a regular link; that''s what CSS is for... > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanThat would be useful if you wanted to use an image for the link. But what if you want the default button for the browser? Craig -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Mar-02 16:04 UTC
Re: Re: More elegant solution for turning link into button?
On Tue, Mar 2, 2010 at 7:54 AM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Just style a regular link; that''s what CSS is for...> That would be useful if you wanted to use an image for the link. But > what if you want the default button for the browser?You don''t need to use an image to style a link to look generically like a button, but yes, if you want it to look like a platform''s native button, then you need to use a form element (or jump through a lot of hoops to try to simulate it). -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 don''t need to use an image to style a link to look generically like > a button, but yes, if you want it to look like a platform''s native button, > then you need to use a form element (or jump through a lot of hoops > to try to simulate it). > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanHow would you style a link to look generically like a button without an image? Sorry for wandering OT into CSS land, but if the answer works, it cuts out some Rails code in my app. Keep in mind that I need the functionality of opening a new window when the user presses a button, which my code currently provides. Thanks, Craig -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Mar-02 16:54 UTC
Re: Re: More elegant solution for turning link into button?
On Tue, Mar 2, 2010 at 8:15 AM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How would you style a link to look generically like a button without > an image? Sorry for wandering OT into CSS land, but if the answer > works, it cuts out some Rails code in my app. Keep in mind that I > need the functionality of opening a new window when the user presses a > button, which my code currently provides.A quick example: <http://webtuitive.com/samples/button.html> -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
> A quick example: <http://webtuitive.com/samples/button.html> > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanAppreciate it, but that''s a heck of a lot of CSS code to get something that approximates the look of a default button ;) Thanks, Craig -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2010-Mar-02 17:48 UTC
Re: Re: More elegant solution for turning link into button?
On Tue, Mar 2, 2010 at 9:42 AM, Dudebot <craignied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Appreciate it, but that''s a heck of a lot of CSS code to get something > that approximates the look of a default button ;)Are you kidding? It''s utterly trivial. And you don''t even have to use most of that if you don''t care about the hover/active behavior. And I would certainly prefer it to creating a form element needlessly for a simple link. But YMMV. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Appreciate it, but that''s a heck of a lot of CSS code to get something > that approximates the look of a default button ;) > > Thanks, > CraigHassan is right that its trivial css implementation. If you feel like learning SASS & Compass, there is the fancy buttons mixin that gives very , well fancy, buttons http://brandonmathis.com/blog/2009/11/19/fancy-buttons-are-here/ Brian -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.