RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

For an indented Ember-compatible alternative to Handlebars templates, you can try Emblem.js

Avatar

It does break nginx to return the wrong header, so it's definitely worth fixing.

Avatar

What is the purpose of the :type column for the User model in the STI example? I don't see the point of this, a User record is never even instantiated?

Avatar

How to make this login work on page tab?

Avatar

In my controller i am using following code to authenticate and to create current_session.

person = authenticate_person!(:recall => "sessions#new")
@current_user = person

but

person = Authentication.find_or_create
& @current_user = person

not working for me, did i miss something?
http://stackoverflow.com/questions/15159926/how-to-authenticate-ready-application-with-omniauth

Avatar

Thanks for letting us know, I've corrected the text in the ASCIIcast :)

Avatar

FYI:

Typo: "The Backbone generator has added underscore, which is one of Backbone’s dependencies, backbone itself and out newly-"

out s/b "our"

Avatar

in Ryan's example, how can I pass a querystring parameter to the datatable class? so if the url is /logs it displays all logs but if it is /logs?product_id=1, it will only display logs for the product with id = 1

Avatar

resources :products do
put :discontinue,:on => :collection
end

Avatar

tried this already and still doesn't work. Any other options? I also added this outside of any groups and still getting the same error

Avatar

All those who come later:

When you're auto generating your 3 questions be sure to make the fields_for line visible using <%= instead of just <% otherwise you won't see the 3 questions.

I'm using Rails 3.2 in case it matters.

Good hunting,

Mike

Avatar

Thank you for this! I was getting very frustrated with not being able to get even the example to work correctly and this solved my problem.

Avatar

the import is seemingly working ok for me but then the values of the attributes are saved as nil. any thoughts?

INSERT INTO "addresses" ("baths", "beds", "building_name", "city", "created_at", "date_available", "full_address", "laundry_in_building", "laundry_in_unit", "listing_notes", "parking", "pets", "price", "showing_contact", "showing_contact_number", "showing_instructions", "state", "status", "unit_number", "updated_at", "utilities_included", "zipcode") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22) RETURNING "id" [["baths", nil], ["beds", nil], ["building_name", nil], ["city", nil], ["created_at", Sun, 03 Mar 2013 16:52:17 UTC +00:00], ["date_available", nil], ["full_address", nil], ["laundry_in_building", nil], ["laundry_in_unit", nil], ["listing_notes", nil], ["parking", nil], ["pets", nil], ["price", nil], ["showing_contact", nil], ["showing_contact_number", nil], ["showing_instructions", nil], ["state", nil], ["status", nil], ["unit_number", nil], ["updated_at", Sun, 03 Mar 2013 16:52:17 UTC +00:00], ["utilities_included", nil], ["zipcode", nil]]

Avatar

You can also use zeus as alternative to spork:
https://github.com/burke/zeus
Comparing to spork it has zero configuration and speed up not only tests executing but all rails commands as well:
zeus console, zeus server, etc.

Avatar

It is possible to have more than one delayed job process doing the same task on the same server?

Avatar

While this comment is 3 months old, I had to chime in on this:

I also typically do auth from scratch, but have lost a job possibility based on that. They felt I was a 'lone wolf' for doing my own auth, and were afraid I could not work well with a team (You know, even though I have worked on teams up to almost a hundred people).

Yes, it probably said a lot about the company and was probably a good warning indicator that that might not be the best company in the world to work for.

Avatar

The problem is that rails asset pipeline will minify your javascript and rename variable names. So you need to pass arguments as strings in the array:
@App = angular.module("App", ['ui', 'ngCookies', 'ngResource']).config(["$routeProvider", ($routeProvider) ->

Avatar

EDIT
the requested 2D array expected by DataTables should be read with ' " ' (double quotes) around the right side of the pair for each attributes

Avatar

Hello

It appears that the JSON array returned is not what is expected by DataTables.

Let say for a model User where mapping returns user.id, user.last_name, user.first_name, user.email...

the returned JSON is

ruby
aaData: [[1, DOE, John, doe@example.com,],[7, BAXTER, Bill, baxter@example.com],[15, BROWN, Bob, brown@example.com],...]

wich is a one dimension array, and the 2 dimensions arraay expected by DataTables (for the aaData part) should be for the same set of data

ruby
aaData: [{"id":1, "last_name":DOE, "first_name":John, "email":doe@example.com,},{"id":7, "last_name":BAXTER, "first_name":Bill, "email":baxter@example.com],{"id":15, "last_name":BROWN, "first_name":Bob, "email":brown@example.com},...]

So if it displays well in your example it throw errors when filtering server-side with an error "JSON data from server could not be parsed. This is caused by a JSON formatting error"

Is there anybody who knows how to return the well formatted JSON ?
Any help would be appreciate

Avatar

Products could have validations like: price can't be lower than 2.99 if the category is "Games" - or something like that :)

Avatar

I found a great unicorn init.d script working with rvm instead of rbenv.

RVM init.d script

Cheers everybody,

Avatar

I suspect he's using Turbolinks which is explained in an earlier railscasts.

I highly recommend it as well. It is stupidly easy to implement and will be adopted in rails 4.0 if I recall correctly.

Avatar

I had to add a comma at the end of path_names in my routes.rb else the server kept giving me a syntax error at this point:

ruby
controllers: {
ruby
devise_for :users,  path_names: {sign_in: "login", sign_out: "logout"},
                    controllers: {omniauth_callbacks: "omniauth_callbacks"}

Great tutorial btw - thanks a ton!

Avatar

Try

ruby
link_to("Delete", product, method: :delete, data: { confirm: 'Are you sure?' })

Cheers

Avatar

Hello Pramsay
I know this post is a bit old but did you solved your problem ? I'm facing the same wall and can't find solution

Avatar

Does anyone found a way to cancel a single upload ?

I did some research and I couldn't find the solution.

Thanks Mr Bates for your great screencasts.

Avatar

When I recently tried implementing this, I landed up with the error "attribute" is marked as readonly . Here, the "attribute" refers to the counter cache attribute. To fix the same, this post helped me.

Avatar

Hi,

how is it possible to a repeat a step? I've combined this Railscast with the Railstcast dealing with nested attributes.

For example: In the first form I will create a question. In the next step I will create an answer and can choose between "Create a 2. Seconds Answer" or "Finish". If I choose to create a second or third answer this should happen in a new form until I decide to finish this record.

Best Regards,
Ben

Avatar

I find the way validation errors are displayed in the third solution a bit odd. The validation error is always the same for each product, isn't it? Might as well display it only once then. Or am I missing something here?

Avatar

I agree Richard, I only use Rails Composer when starting a new Rails app.

Avatar

An if it does, how it works? Does it re-minified applications.js, I thought that application.js was cached through all requests.

Thanks,
alfredo

Avatar

Does Gon work on production, when asset pipeline is on and js minified?

Avatar

+1. Just hang in there. I was getting nervous because the server had actually been running (green light in the UI) on AWS for awhile. It did eventually kick in.

Avatar

This is more of a papertrail, not activity tracking.

Avatar

It is articles_controller.rb not calendars_controller.rb

Avatar

usersdatatable.rb

def data
    users.map do |user|
      [
      link_to(user.name, user),
      h(user.email),
      link_to("delete", user, method: :delete, data: { confirm: 'Are you sure?' }),
      # check_box_tag('user[]', user.id)
      ]
    end
  end
  • it don't working When i add check_box_tag. Please help me!
Avatar

Absolutely unbelievable. My partner and I just finished building this very type of functionality into an app. It took us months to figure out a plausible approach, and here it is in 15 minutes. Someone give this man a medal.

Avatar

Saving works, but there is no redirect when saving. Anyone else having this issue?

ruby
Mercury.on('ready', function() {
    var link = $('#mercury_iframe').contents().find('#edit_link');
    console.log("mercury ready ready", link);
    Mercury.saveUrl = link.data('save-url');
    link.hide();
});

Mercury.on('saved', function() {
    window.location.href = window.location.href.replace(/\/editor\//i, '/');
});
Avatar

I also have an issue, but with the SQL that is produced by the relationship between User and micropost (like haiku in the Railscast).
I posted it on stack overflow, would love it if someone could help.

Avatar

This also works (IMO is preferred) in rails 3.2

Avatar

Is there a way to follow this same direction for a partial? My view starts with a form that passes params back to the same URI which formats a partial. I'm struggling to make this lesson translate to my scenario. Advice? Ideas?

Avatar

I am not quite familiar with the concept of Presenters. Can you recommend any articles/videos on the topic?

Avatar

Could be my setup but Mercury is running 'onload' twice. i had to do one of these:

ruby
       var link = $('#mercury_iframe').contents().find('#edit_link');
         if (typeof link.data('save-url') != 'undefined') {
             console.log('only set saveUrl if it exists');
             Mercury.saveUrl = link.data('save-url');
         }
        console.log(Mercury.saveUrl); //<-- should be valid
        link.hide();