RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi, this looks great. Trying it out, but encountered an error:

uninitialized constant Mime::PDF

...
require "pdf/writer"
Mime::Type.register 'application/pdf', :pdf
...

...
          format.pdf do
            pdf = PDF::Writer.new
            pdf.text "test"
            send_data pdf.render, :filename => 'threads.pdf', :type => 'application/pdf', :disposition=> 'inline'
...
          end

Thanks for any help!

Avatar
Matthijs Langenberg on #123 Subdomains 2008-08-22 11:09:11

I've actually taken this a step further by also rendering a different set of templates per blog.
So instead of rendering from /app/views, the app renders /app/views/domain. So it's one rails app serving n-blogs on full domains.
Get in tough with me if you want to share your thoughts on this topic.

Avatar

Same Problem for me getting autocomplete to work with fields_for.

If anyone would get that to work I would appreciate a small hint on this thread :P

regards

Avatar

Ok, I just added the :multipart => true to the form_field and it works. Should have tried before....

Avatar

Does anyone know how to use fields_for with :multipart => true in order to upload images?

Avatar

Hi,

i want to get the same effect with that auto_complete text field, but using class instead id, is that possible?

Avatar

@Marc, interesting, I didn't realize "new" worked when called through associations. But looks like it does from my brief testing. Anyone know if there are differences or side effects?

Still, "build" seems to be the convention so I'll probably stick with it, and "new" is kind of reserved for Ruby which is why I'm surprised it works.

Avatar

I'd like to use this to replace the example in the #59 Optimistic Locking railscast, but I'm not having any luck in getting it to work. Of the fields in conflict, I'd like to show the field name that changed, what the value of the field was and what the user changed it to. Any help would be appreciated. Thanks.

Avatar

The latest commit of PassengerPane to GitHub includes an "Aliases" field that takes care of the ServerAlias addition to the vhost AND updates your hosts file.

Avatar

@Ryan:
I just tested your project from github, and it does work.. Very strange, I cannot see any differences compared to mine (the only difference is that I'm using my work computer now, and yesterday personal, comp. But both running leopard with passenger on original apache and so on). I will try again later today, doing once again from start and see what happens.

Avatar

I actually have a question which I've been meaning to ask for a while. Why do you use build (as opposed to new or create). I know build just makes the object in memory.. but doesn't new do the same thing (until you save it)?

Avatar

Hi, i followed the steps about the auto_complete and it works great!
but i need to add N more textfields with auto_complete in the same form (for example Complex Forms),
and i don't know how to do it, can you give me a hand with this? :(

Avatar

Does this allow for renaming of columns? Something like this:

script/generate migration rename_description_to_task teaser:string

Avatar

@kenny, hmm, that's strange. Try downloading the project for this episode and see if you get the same behavior there.

http://github.com/ryanb/railscasts-episodes/tree/master/episode-123

Avatar

I have the same issue as Jeff..(i think) No matter what I specify in the conditional regex, it matches and sends me to the show action instead of falling through to the map.root ..

example, both test1.project.local, test2.project.local and project.local takes me to the show action of the controller..

Avatar

Is there a way to place many of these auto complete fields on one page? When I dynamically add more of these elements to my page (I need N topics with descriptions) the other auto complete fields don't work, I suspect because the div IDs are the same. Do you know of a way to fix this?

Avatar

So I might be over looking or just being a little paranoid here, but I'm having an issue with getting a site to run under Passenger, that runs perfect under Mongrel. When I access the site via Passenger I noticed that it's looking for Ruby here /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems, but I've actually installed Ruby here /usr/local/bin/ruby. When I run the app under mongrel (which uses /usr/local/bin/ruby) I don't have a problem. When when it looks in the other place it seems to have an issue with gems.

I know that one of the lines that you are supposed to put in the httpd.conf file goes to this /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems, so I'm wondering if I could just change that to this /usr/local/bin/ruby.

BTW, I'm running Leopard and compiled my own version vs using the pre-installed from Apple.

Avatar

@Michael, thanks for catching that. Fixed the show notes.

Avatar

Please don't use wildcard CNAMEs. Use wildcard A records, if you set up your own DNS server.

*.example.com. A 127.0.0.1

Avatar

Just as a note, all javascripts should be included at the bottom of the page right before the body close tag. It's better performance wise.

Avatar

I am currently using mislav-will_paginate gem.
When I give it in environment.rb, it shows me 'mislav-will_paginate' file not found. I have given the proper version and source. Still it shows me the same error. How can I get rid of this error?

Avatar

I've had no problems with railscasts on Linux. VLC doesn't work for me (I get audio, but the image freezes on the intro), but MPLayer works perfectly. (dev-SVN-r26753-4.1.2)

Thanks for the cast, Ryan.

Avatar

I have this setup and it is working properly, but I do have a problem:

if I go to a static site in my user's "Sites" folder (http://localhost/~username/static_site/), all the css stylesheet links are broken because of a routing error from the rails app which is running.

The top rails app in the Passenger pref pane runs as localhost, so I don't know how to get around that. Can anyone help?

I've done some mucking around in /etc/apache2/ but haven't had any luck... thanks!

Avatar

For anyone getting: "Can’t find the Phusion Passenger Apache module" with the Passenger PrefPane...

Following Ryan's instructions and copying the three lines into the Apache config file, I *finally* realised that the lines in the show notes refer to passenger 2.0.2, whereas I have installed 2.0.3. A silly mistake, but I can't believe I'm the only one that fell for it!

Thanks for the great screencasts, Ryan! :-)

Avatar

On Ubuntu 8.04 I had the problem that static images and stylesheets were not being loaded.

To the set of directives Ryan provided

<directory "/Users/rbates/code/railscasts/public">
    Order allow,deny
    Allow from all
</directory>

I had to add two directives to make it work:

<directory "/Users/rbates/code/railscasts/public">
   Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
</directory>

(However, before I did that I checked that my permissions on /public and relatives were right like James Edward Gray II explained.)

Good luck!

Avatar

same here... maybe a gems 1.2 issue

Avatar

Awesome - I've been looking forward to this one :) Very handy for lots of my future projects.

Avatar

@jeff, what is the "wrong url"? It should be going to whatever you specify with "map.root" when not passing a subdomain.

@Nelson and Kurt, I'm hoping to release the episodes in a more Linux friendly format in the future. Thanks for your feedback.

Avatar

I also have problems viewing the movies in Linux. I have tried Kaffiene, VLC, xine, and mplayer. The problems started around episode 100. One player shows the video but doesn't play the sound, one plays the sound but the video is extremely choppy, one crashes and one does nothing. Maybe you changed some settings that affect the mov file?

I used to watch your screencasts religiously, but now I study the notes deeply instead. So your work is still incredibly useful to me, and engages my brain even more. I just don't get the full effect most of the time...

Avatar

I can't see the videocast in Linux (mplayer, vlc or totem) ... In fact I can see the video, but it's very slow, like 1 frame per second....

Avatar

subdomain-fu is pretty cool. We used it in http://hoptoadapp.com

One problem we had with subdomain-fu was that it broke autotest for the app. So, I forked and ham-handedly removed the autotest directory - http://is.gd/1IIT

On the topic of subdomains, I wrote (but haven't used yet in an app) a copycat of the excellent validates_email_format_of plugin for subdomains that someone might find useful - http://is.gd/10hL

Avatar

Great work ryan. I have everything working really well. Except for one thing. The conditions regular expression does not seem to be working. It still goes to the wrong url when there is no subdomain. I thought maybe it wasn't working so I tried it out. I hard coded a subdomain :subdomain=>/test/ and it worked as expected. I'm just curious if I am missing something. again thanks for all of your awesome free screencasts

Avatar

Thanks for the awesome cast, I will be using this in an upcoming project :)

Avatar

@Mike, I believe Basecamp does not make separate tables or databases for each subdomain. It's just one database with multiple tables split by models just like Rails does.

Usually when you're working with subdomains like this, you'll have a model which maps directly to the subdomain which you load in a before filter like I do here. In Basecamp the model could be Company, not Blog.

You then always fetch other models through the associations as I show in the episode. This way they're always scoped properly and you can't access models outside of the company/blog.

Avatar

Fantastic episode, thank you.

I have an enterprise type question: If we take 37signals' Basecamp as an example of what we want to achieve in terms of separating customers logins and data by subdomain, presumably each database table would need a subdomain ID reference or else the whole thing would be a mess.

Is it normal to have one massive database (with the help of clustering, load balancing etc) or 1 database per subdomain (which presumably would be routing hell).

I just wondered what conventional wisdom is and how well this model scales?

Avatar

Cool, I’ve been waiting for this episode. Thanks.

Avatar

Hello, first, thank you Ryan, you are doing a very good job here!

I just want to point out that the link to the "EPISODE 111" LEADS actually to "EPISODE 108".

But many people here are smart enough to get through that issue.

Avatar

Please disregard my previous posts, I was able to solve this. I needed to add some code to the <head>

Avatar

Please disregard my previous posts, I was able to solve this.

Avatar

@Tim, next episode is on subdomains and I'll mention a couple alternatives in the show notes. :)

Avatar

Hi Ryan,

The method missing definition really helps clean things up.

I just implemented something similar to this on a project and I noticed that some of that somethings weren't making it to the view.

After fiddling with it for a bit I realized that the methods I was calling (for example: puts) already existed in the scope of the object so it wasn't sending them to @template and so the output wasn't making it to the browser.

This was easy to correct my explicitly calling @template.puts but, I'm just wondering if you know a cleaner way. :)

Thanks.

Avatar

I have found using squirrel with some modifications to resource_search allows for much of the above, with little addititional work. With squirrel, there is little reason to ever build your own SQL WHERE clauses manually again.

Avatar

Oh yeah, and I'm using Rails 2.1 if that makes a difference??

Avatar

I'm trying this code (I'm a noobie) but get the following error:

RJS Error:

ReferenceError: Insertion is not defined.

Avatar

First, let me say 2 thinks - 1) I'm a noob and 2) I really appreciate these!!

I tried this with rails 2.1 but have some problems and not sure if it's do to how 2.1 works or due to my noobiness. When I tried this, it doesn't actually save the tasks, only the project. Also, my screen doesn't show the 3 tasks as part of the record as your screencast does. What gives? Any ideas?

Avatar

Hot episodes!

Congratulations and thanks for all the great episodes guys

best regards

Avatar

Why not tell us total noobs about how you created the home controller and where you put that code for index.rhtml (for completeness)
noobs are like gravy we run all over the internet looking for holes

Avatar

Yes, I'm having issues with this method and a date_select as well. When submitting the form it throws a:

Status: 500 Internal Server Error
  Conflicting types for parameter containers. Expected an instance of Array but found an instance of Hash. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value. (The parameters received were {"date1(1i)"=>"2008", "date1(2i)"=>"8", "date1(3i)"=>"15", "date2(1i)"=>"2008", "date2(2i)"=>"8", "date2(3i)"=>"15"}.)

Any ideas?

Avatar

Great screencast, Ryan!

Is there an easier way to set up subdomains using the Passenger Pref Pane, besides editing the hosts file manually?

Thanks,

-- Tim

Avatar

Thanks for the awesome screencast Ryan!

Just wanted to add a few comments, that you may or may not already know;
- You can also add applications by dragging the application folders onto the source list.
- You can easily edit the vhost configs by dragging applications from the source list onto, for instance, your text editor.

Keep up the good work!

Cheers,
Eloy Duran