More elegant solution for turning link into button?

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:

def button_link( label, path, *features ) # makes a link look like a button linktext = " 0 # opens new window, assigns features linktext << "window.open('" << path << "','" << label << "'" features.each { |feature| linktext << ",'" << feature << "'" } linktext <' else # opens in same window linktext <' end end

Which works as expected in the view, e.g.

<%= button_link( ‘Print’, url_for( … ), ‘new_window’ ) %>

But feels kind of hacky. Does anyone have a more elegant solution?

TIA,
Craig

On Tue, Mar 2, 2010 at 7:26 AM, Dudebot [email protected] 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 S. ------------------------ [email protected]
twitter: @hassan

Just style a regular link; that’s what CSS is for…


Hassan S. ------------------------ [email protected]
twitter: @hassan

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?
Craig

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 S. ------------------------ [email protected]
twitter: @hassan

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.

Thanks,
Craig

On Tue, Mar 2, 2010 at 7:54 AM, Dudebot [email protected] 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 S. ------------------------ [email protected]
twitter: @hassan

On Tue, Mar 2, 2010 at 8:15 AM, Dudebot [email protected] 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 S. ------------------------ [email protected]
twitter: @hassan

On Tue, Mar 2, 2010 at 9:42 AM, Dudebot [email protected] 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 :wink:

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 S. ------------------------ [email protected]
twitter: @hassan

A quick example: http://webtuitive.com/samples/button.html


Hassan S. ------------------------ [email protected]
twitter: @hassan

Appreciate it, but that’s a heck of a lot of CSS code to get something
that approximates the look of a default button :wink:

Thanks,
Craig

Appreciate it, but that’s a heck of a lot of CSS code to get something
that approximates the look of a default button :wink:

Thanks,
Craig

Hassan 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs