RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

been using this for a while myself, along with flutie, also by thoughtbot

Avatar

I second using bootstrap-sass. I supports the current version of Bootstrap and makes it so much easier to customize.

Avatar

travis-ci told me that it works on all rubies, jrubies and rbxes

Avatar

anyone know how to make jbuilder pretty print?

Avatar

Nevermind, accidentally had two bootstrap gems included (one based on 1.4 and one based on 2.0) and the wrong version was included.

Avatar

How can I add my own icon sprite? I see we're setting the variable here:
@iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png');

However, where in my project would I put my "icon-sprite.png" file. There's no twitter/bootstrap folder anywhere.

Thank you.

Avatar

Javascript works fine without semi-colon, they're not necessary. It's not like you're gonna be modifying their javascript files. You can still use them in your javascript functions.

Avatar

When I call entries.create my Rails app logs a GET request to /api/entries instead of a POST with params. Saving an updated entry works just fine.

I'm even getting this behavior running the railscast code from github.

Should I be using a different server than webrick?

Avatar

Can anyone point me in the right direction getting this to work with file uploading? I've tried just sort of mashing file uploading in there, but you can't store files in a session variable (you get type error, can't dump file).

Avatar

hmm, you could use wordnet in order to extract synonyms and hypernyms and add them to the search

Avatar

Good question, I am currently having the same problem.

Avatar

great. but when I typed "mongo" in the search box on the main page I can not find this episode (

Avatar

Windows has an embedded runtime which can be used by execjs, you don't need to specify anything, it should just work.

Avatar

You can use the pry-rails gem to automatically use pry as the Rails console.

Avatar

Great Gem Ryan. Thank you!
I am trying to set up Private_Pub for my application.
I need to display a list of all the users who are online at a given time.
Any ideas how to do this???

Avatar

I'm having trouble getting the navbar working. I'm using bootstrap-sass, haml and simple_form. What could be wrong?

Here is a screenshot of what is happening

It's like some of the CSS is not applied.

Avatar

I used this for an asset management app I'm writing.

Instead of countries/states, I use Makes/Models (which belong to an asset).

Anyway, if you are loading a record that has a make/model saved (or a country/state) then the model (state) will be hidden and you will have to change the make (country) to re-enable it. Then you will have to know it's saved value. So I changed it to only hide the model (state) if there is none saved.

coffees.js
jQuery ->
        loaded_model = $('#asset_model_id :selected').text()
        if loaded_model.length < 1
                $('#asset_model_id').parent().parent().hide()
        models = $('#asset_model_id').html()
        $('#asset_make_id').change ->
                make = $('#asset_make_id :selected').text()
                escaped_make = make.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
                options = $(models).filter("optgroup[label='#{escaped_make}']").html()
                if options
                        $('#asset_model_id').html(options)
                        $('#asset_model_id').parent().parent().show()
                else
                        $('#asset_model_id').empty()
                        $('#asset_model_id').parent().parent().hide()
                        

I also used parent().parent() because I am using with SimpleForm

Avatar

what does "supposed to" mean in this context? "more subject to hacking?", "client side runs slower", etc.? Is there an actual technical downside, other than stylistic preferences?

p.s. I put my js curly braces on their own line. Cuz I'm a rebel and that's how I roll.

Avatar

I just read a 37signals post on their caching technique in Basecamp Next and came here for some informations about partial-caching etc.

I think David explains very well, how you can use a technique like this very smart, to get fast responses: http://37signals.com/svn/posts/3112-how-basecamp-next-got-to-be-so-damn-fast-without-using-much-client-side-ui

Avatar

@lazylester - you probably got an answer already.

The screencast and what Ryan mentioned are indeed authentication because they help you keep trail of all activities for a digital identity. This is what most public websites need. But if you need some link between the physical person and digital id (for example to prevent 1 person from having multiple accounts) you can use an approval flow. Look at authentication gems such as devise. Devise allows you to mandate approval of new registration.

There are other strategies worth looking at too. For example, Google encourages people to link their account(s) to a mobile number. That way even if a person has multiple google accounts, they can be linked together via a common mobile number. You need to decide what works for your application.

I hope that helps.

Avatar

It is not meant to be used for such forms (e.g. form_tag based forms which do not have an underlying model).
it is meant to be used for the forms which are connected to an underlying data table which happens to be majority of forms for a CRUD based Rails application.

Avatar

This has nothing to do with Ruby. Ruby was never ment to have semicolons. JavaScript is supposed to have semicolons at the end.

Avatar

jayeshmori, Ben,

My way to solve that issue:

Use the column name with a table alias, for example: 'us.name'.
In the controller, always retrieve info joining the other table, with its alias 'Product.joins('JOIN table alias ON field = field')'

And then use as the column name, the alias + the column name, as I stated before.

And remember to include this 'special' name in the valid column names in the sort_column private method.

Hope it helps!

Avatar

How would SimpleForm work with a form that isn't associated with an object? For example, a login form.

Avatar

I'm having problems getting the gem to work with a rails 3.2.2:

ruby
undefined method `ends_with?' for #<Pathname:0x00000105898040> (NoMethodError)
Avatar

The jruby-rack-worker gem comes to the rescue: http://github.com/kares/jruby-rack-worker. It lets you still use delayed_job to schedule jobs, but provides a different way to kickoff worker processes that is more friendly to JRuby and also works on a windows tomcat server. I'm not advocating deploying on windows, but if you're forced to do that for some reason and you also need to use JRuby -- take a look at jruby-rack-worker.

Avatar

Does anyone know how to put the flash messages back in Rails 3.2.1??

<%= debug flash %> is empty.

Avatar

I'm using that now, it works like a charm and saves a lot of markup :)

Avatar
erb
<%= f.input :name, :wrapper_html => { :class => 'input-section' }, :input_html => { :class => 'input_form', :placeholder => "name" }%>

You can have SimpleForm to generate those wrappers by default, so you won't clutter your views with styles.

The docs are really easy to read, well written.
https://github.com/plataformatec/simple_form

Avatar

In Rails 3.1 there is a nicer way to handle conditional attr_accessible calls. See this blog entry.

The argument over Rails' default permissions for mass assignment was reignited after GitHub was hacked on March 4, 2012.

A Russian GitHub user, Egor Homakov, was arguing for more restrictive defaults, but he was rebuffed over a three day period. To make his point, he exploited this weakness on GitHub, where some model attributes were not protected in the code that handles public key submissions, in order to submit this commit to the rails master branch.

As a result, several commits were made to make whitelisting of model attributes the default behavior of rails generators. We will see if these modifications actually make it to the next release of Rails.

Avatar

how woud someone use simple form to generate something like below. As you can see the input is wrapped with a div.

erb
<div class="input-section">
        <label class="label_form">Label<span>*</span></label>
        <div class="input_form">
                <input type="text" id="form_input" name="name" placeholder="name">
        </div>
</div>
Avatar

Please have a look on my project, I've fork the seyhunak project to use directly the official source of bootstrap.

So each time twitter bootstrap is updated you can get it directly in your rails project!

https://github.com/keysen/twitter-bootstrap-rails

Avatar

Unfortunately if the app uses one dyno 24x7, the app cannot use the free quota for the worker as well. :/

Avatar

Hey Nuno, I created a tool to help people to test HTML e-mails.

The tool, called Puts Mail uses Premailer to check HTML warnings and to make the CSS inline. ;)

But I think that your concern is more about the screencast Sending HTML Email, no?

Cheers,
Pablo Cantero

Avatar

for some reason, I just removed ":cache => true" from my application.html.erb file and the problem went away. When I did have it I kept getting a "wrong number of arguments (3 for 2)" error that pointed to line #6:
<%= javascript_include_tag "jquery","application", :cache=>true %>
in application.html.erb.

I still cant figure out whey this was breaking the app!

Avatar

Do you use semicolons in ruby, too? scnr

Avatar

Irrelevant for 3.2.2, rails bug or API change?

Avatar

hi everybody,
i use will_pagine to navigate through a long table. how do will_paginate remember the checked checkboxes.
I need your help
thanks in advance

Avatar

Anyone else getting javascript errors with the Sass variation, i.e.

"$("a[rel=popover]").popover is not a function
[Break On This Error]

$("a[rel=popover]").popover();"

Looks like for some reason the bootstrap js files aren't getting served up.

Avatar

I had to use database_cleaner to clean up my testing database before each test:

ruby
require 'database_cleaner'

DatabaseCleaner.strategy = :truncation
class MiniTest::Spec
  before :each do
    DatabaseCleaner.clean
  end
end

This does not use transactions, although it should be possible somehow with database_cleaner. They have an RSpec example on their GitHub page which maybe could work.

Avatar

Ryan could have done this because it's more Ruby 1.9 to omit the hash rocket now and personally I think his syntax is looking cleaner.
But you're right that the as: option is unnecessary.

Avatar

I added rack-pjax and it works but there is always an extra "&" at the end of the URL shown in browser bar even if my link doesn't have it. This breaks my link_to_unless ...

If I remove
$('.navbar a').pjax('[data-pjax-container]')
from my .js.coffee file, the & goes away.

Example link I use in my application navbar
<%= link_to_unless(params[:category].to_s == "Application", "Application", {:controller => "top10", :action => "index", :category => "Application"}) %>

In Chrome 17, when I hover this link, it shows
http://localhost:3000/top10?category=Application
but when I click it, the current URL in the top Chrome bar is
http://localhost:3000/top10?category=Application&

Any idea ?
Thanks

Avatar

You can also set config.active_record.whitelist_attributes = true in config.

Avatar

You can pass a block to f.input or f.association call and use rails form helpers there like this:

erb
<%= f.input :state do %>
  <%= f.grouped_collection_select :state_id, Country.order(:name), :states, :name, :id, :name, include_blank: true %>
<% end %>

Doing so, you get simple_form's, label, hint and other stuff, but overwrite only the actual input to the one you need.

Avatar

DelayedJob doesn't seem to work with JRuby unfortunately, at least not on windows -- as best I can tell. It will queue jobs, but starting a background job fails.

Avatar

Nevermind, my validations were failing because I had filtered them to only occur :on => :create.