Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

I trying to create a nice button using bootstrap

I'm working on my buttons and somehow this is not working at all. The line code I'm changing looks like this:

<td><%= link_to "Details", controller: "companies", action: "show", id: sbr.id %>

And I'm adding btn btn-primary to make it look nice but nothing happens;

<td><%= link_to "Details", controller: "companies", action: "show", id: sbr.id, class: "btn btn-success" %>

Any Ideas

Seth Kroger
Seth Kroger
56,413 Points

I've edited your post for formatting.

Does bootstrap work otherwise in your app? Did you include the gem for it in the gemfile and have no trouble installing it?

3 Answers

Seth Kroger
Seth Kroger
56,413 Points

I had to look this up but if you are using the controller/action syntax instead of a route with the html options it needs to be in its own hash like:

<td><%= link_to "Details", {controller: "companies", action: "show"}, id: sbr.id, class: "btn btn-success" %>

See the API docs for link_to, in the middle of the examples section. http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

I tried but it gives me an error like this: No route matches {:action=>"show", :controller=>"companies"}

Ralph Cacho
Ralph Cacho
8,698 Points

Hello Ivan,

Make sure you have the Bootstrap library included in your project. The easiest way to do this is using their Bootstrap CDN (mentioned at http://getbootstrap.com/getting-started/):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

Once you have that included, you should be able to use it like this:

<button class="btn btn-primary">Send</button>

Let us know if that helps. Good luck!

boot strap is working and the link does work and I just can't figure why the btn would appear on page do I have type it in different way?

Mr, Kroger bootstrap is working and I didn't know there was a gem for bootstrap?