RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Great topic.

One problem I've had with importing CSV files from real users is often they aren't always valid, i.e., they include extended characters, are encoded weirdly, or are otherwise malformed leading to many parsing errors. Finally if they include headers at all they do not match that names of the attributes in the Rails model.

The users who send me files like these are also the least technical so hardest for them to clean up themselves or understand why files are invalid.

Would like to see more about error handling, or know what people do with these real world messy files. Thanks.

Avatar

When trying to tag an article, lets say "chemistry, sept 20/2012" as in want to organize all the articles posted on a certain date.
How do you rewrite the routes.rb:
get 'tags/:tag', to: 'articles#index', as: :tag
in order to access tag names that embed "/" forward slash?!
I get this error when I try to access sept 20/2012:
No route matches [GET] "/tags/sept%2020/2012"

Avatar

I am getting this error through signin process "The token URL or xdReceiver has not been whitelisted". I visited their support blog but I didn't find anything useful.does nayone knows how to solve that??

Avatar

I must say that I completely disagree with these latest sentiments. I think that every developer should spend time understanding the tools that they use (which INCLUDES reading the source code). I don't consider developers who use rails to be exempt to this.

Rails is complicated and intertwined (as you can see from the screencast). Most people, when first viewing the code get overwhelmed quickly. These walkthroughs show how you should read through source code and put together the pieces to gain an understanding of how things are put together.

I, for one, applaud the effort spent on more 'advanced' screencasts.

Avatar

Definitely interested in this

Avatar

It would be neat if you showed how to make the slugs unique only to their parents and not site wide.

Avatar

If you aren't creating too many of these routes I think the best way to do this is with static routes - e.g. get "/pricing" => "pages#pricing". It isn't strictly restful, but I think people sometimes go overboard with that. Not only is this simpler, but it also avoids the catch-all route issue mentioned as well as database performance issues brought up.

Avatar

Found the issue which was that it an edit needs to be made for it to work with existing entries on Heroku :)

Avatar

Friendly_ID was working for me before I edited by After editing the _add_slug_to_users.rb file then ran the command User.find_each(&:save)

For each user, I got an error that was similar to:

User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("slug" = 'carleton-howell' OR "slug" LIKE 'carleton-howell--%'ESCAPE '\') AND (id <> 2) ORDER BY LENGTH("slug") DESC, "slug" DESC LIMIT 1
User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('example-1@railstutorial.org') AND "users"."id" != 2) LIMIT 1
(0.1ms) rollback transaction

Avatar

no problem, i remember that biting me in the butt once too :/

Avatar

Hi,

I need files to be renamed before uploading
I get this to work :

ruby
    def key
      @key ||= "uploads/#{SecureRandom.hex}"
    end

But I need the extension at the end and this doesn't work:

ruby
    def key
      @key ||= "uploads/#{SecureRandom.hex}" + File.extname("${filename}")
    end

Thanks for the help

Avatar

For simple to_param overrides that append a name to the ID, I wrote a really simple gem called pretty_param. You can check out the logic https://github.com/kaiuhl/pretty-param/blob/master/lib/pretty_param.rb, but essentially it's just a better DSL for the most common to_param overrides with better filtering of special characters.

Avatar

Hi adam-pl,

This is a really great solution! I've been searching all over for something like this and managed to implement without a hitch. One question though - is there any way to stop if spawning a new page every time you click on a link, and so it simply send you to the link path rather than creating another separate page with url?

Thanks!
Mark

Avatar

In addition to the resources mentioned in this cast, you could also check Ohloh to see some interesting statistics about the project's code, or even to compare two or three projects. For example, Ohloh's page for Devise shows how long the project has been active, and how many active contributors worked on it over the years.

Avatar

Nice episode, one question... I am trying to integrate this with facebook login using omniauth, but the return url using this configuration will be "unicorn" what doesn't match the url on facebook app. How can I make facebook accept this configuration? Thanks for any help.

Avatar

With mercury 0.9 the posted js didnt work for me anymore so I tried araound a bit... This works for me, maybe somebody needs this,...

javascript
jQuery(window).on('mercury:ready', function() {
        var saveUrl = $("#edit_link").data("save-url");
        Mercury.saveUrl = saveUrl;
});
Mercury.on('saved', function() {
        window.location.href = window.location.href.replace(/\/editor\//i, '/');
});
Avatar

You need to hook the remove method into a callback function which is executed once the fadeOut method finishes, like so:

$("#item_div").fadeOut("500", function() { $(this).remove();})
Avatar

I'm pretty much a noobie when it comes to writing jQuery and am trying to fade out an item as it is deleted. I have tried the following in my destroy.js.erb file - the item is deleted but does not fade away so stays on the page until the page is reloaded.

ruby
$('#item_div').fadeOut("500").remove()

If I take out the fadeOut part, it successfully disappears from the page.

Would someone mind pointing me in the right direction?

Avatar

It's good to have a constraints: { format: :html } so images and other files 404 correctly. Otherwise you're going to get a lot of 500's

Avatar

?? I used the above solution from ziemekwolski and I still get nothing back when i search for say "anky" but I get results back when doing:

@dr_wallaches = DrWallach.where("callers like ? or monologue like ?","%#{params[:search][:terms]}%","%#{params[:search][:terms]}%")

Avatar

can you please explain how multicolumn search? i implemented the code of ryan from episode 340 and i have problem to implement multi column seach. if you can also post some code it will be really awesome.
thanks in advance

Avatar

Ryan, Over the years, I have benefitted from your RailsCasts a lot. So I say this with nothing but sincere appreciation for what you have done and are doing for the Rails community. I totally second Sergey Kuleshov is saying above.

Please focus on specific topics that can be useful for a Rails developer and leave the innards of Rails to the Rails core team members and others who might be interested.

Avatar

How can we implement Ransack gem with Datatables gem?

Avatar

I am sorry to say but the walkthrough videos aren't the best of your creations. What I value a lot in your normal screencasts is that they scratch a very specific itch and show how to integrate thing that wouldn't otherwise be obvious.

I am not sure which purpose the walkthroughs server though. They are very generic, moreover experienced rails devs can read the code and figure this stuff out. Novice developers will feel lost anyway.

Avatar

I got following Error:
Error: A field was longer or shorter than the server allows.

Avatar

I did this with the jquery-raty-rails gem and it works quite well.

My current problem is displaying the value of the vote the current_user gave to my model. The average vote for my model is no problem via Model.reputation_for(:votes)

Avatar

Luis's suggestion has many options including removing the slider. Check out all the examples and most likely one of them will fit your needs

Avatar

Thanks for this! I signed up for Pro just to watch this episode... I think it would be great to include a version of this that would work with a mobile app using backbone. Any advice on how to do that?

Avatar

I have since separated the two since it was causing even more problems when I was plotting the events on the calendar. I know its not the best solution to separate the date and time as two data fields but I got it working rather painless.

Still would love to hear any better ideas

Avatar

so I have a datetime field in my modle and I have seperated them by:

ruby
%p
    = f.label :event_date
    = f.date_select :event_date
    %br
  %p
    = f.label :event_time
    = f.time_select :event_date, :minute_step => 15, :ignore_date => true, :ampm => true
    %br

and this works fine. I have then change the date select to a f.text_field and applied whats discussed in the video. and I produce this error:

1 error(s) on assignment of multiparameter attributes

{"utf8"=>"✓",
 "authenticity_token"=>"YHlnywsS5yAA2gCp4iU+RQNGEC1i+VzMz2FQab8r+a0=",
 "event"=>{"event_name"=>"",
 "event_date"=>"2012-12-21",
 "event_date(4i)"=>"14",
 "event_date(5i)"=>"00",
 "participants"=>"5"},
 "commit"=>"Create Event"}

If I comment out the f.time_select line like so:

ruby
%p
    = f.label :event_date
    = f.text_field :event_date
    %br
  %p
    = f.label :event_time
    /= f.time_select :event_date, :minute_step => 15, :ignore_date => true, :ampm => true
    %br

everything works fine except that the time is saved as 00:00:00 of course. Any one have any clue on how to get this working right?

Avatar

So dumping orders array into data-attribute exposes all the attributes stored in db to Morris. What would be the best way to inject virtual attributes to the objects in array handed over to javascript side?

Avatar

I've also had the same problem.

The reason is unicorn_init.sh file doesn't have execute flag on server site.
To do that let's add following line into deploy.rb at :symlink_config task section:

ruby
sudo "chmod +x #{release_path}/config/unicorn_init.sh"

Finally :symlink_config task's code is:

ruby
  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    run "chmod +x #{release_path}/config/unicorn_init.sh"
  end

You do not have replace any run into sudo.

For me it works fine.

Avatar

These walkthroughs are great. I used to have time to do such research but working and school make it impossible. Worth the membership fee for sure.

Avatar

Any other plugins you guys like?

Avatar

Thanks for this episode.

Is there a technical reason for chosing the "Ancestry" gem rather than the "Awesome nested set" gem ? The second one seems to be more popular for few months no ?

I'm afraid that, if I start building my app with Ancestry, it could be deprecated in few weeks. :/

Avatar

Thank you ryan and keep it always up :-)

Avatar

I second the comment above, this episode should be revised, please!

Avatar

I follow the tutorial closely but my "Add Question" does not work. When I click on it, nothing happens. When I look into Chrome developer tool, it does not seem like the javascript is executed. Can anyone advise? What are the things I could possibly miss?

Avatar

While I was thinking about it, I migrated to Turbolinks. Since I use bootstrap, I needed the https://github.com/kossnocorp/jquery.turbolinks gem to deal with the fact that bootstrap binds events to the body tag (this will be fixed in future releases to use the html tag).

Also, I use Turbolinks for my forms (like search) that use GET

javascript
  $('form[method=get]:not([data-remote])').on 'submit', (event) ->
    event.preventDefault()
    Turbolinks.visit @.action + '?' + $(@).serialize()
Avatar

Adding it outside the :production group works for me
(assets weren't being found in :development)

Avatar

I thought simple_format might be new... then I found that it was added 8 years ago :P

Avatar

I use the old hash syntax for state transitions for the same reason. An good example of where language syntax flexibility is neat.

Avatar

It was easy (1-2 days) for me to migrate my Rails 3.2 desktop app to use PJAX via the rack-pjax gem. I picked that gem because you specify the container. I chose to just PJAX the content between my header and footer tags.

However, I have a feeling that most of the performance win comes from not reprocessing the head tag so I would expect that just fragmenting the entire body is good enuff. When I get the time, I'll migrate from PJAX to Turbolinks.

Has anyone had any experience integrating either PJAX or Turbolinks with jQuery Mobile. JQM does has it's own pushState manager and converts all links into AJAX requests. It also does DOM caching of those pages so there are several issues to consider.

Avatar

Anyone realize that tokeninput doesn't work on IE9? Seems like a pretty obvious no-go considering 17% of the internet still uses IE.