RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi I have a problem, only the first row of my table is the right chosen dropdown and the next rows are not.

my code

<table>
     <thead>
         <th>Item Name</th>
     </thead>

      <tbody>
         <% @purchases.each do |p| %>
           <tr>
               <td>
                    <select title="Choose an Item..." id='form_field' style="width:350px;">
                     <% @items.each do |i|%>
                        <option value = "<%= i.id%>"><%= i.name%></option>
                    <%end%>
                    </select>
              </td>
          </tr>
         <%end%>
<table>

<script>$("#form_field").chosen()</script>

Avatar

Thank you for refactoring this code. The associated objects are especially useful rather than masking each attribute behind a method.

I was having the same thoughts as Travis!

Avatar

Postgres isn't the only database that provides Schemas. You can achieve the same thing in Oracle with Schemas and Public Synonyms.

Avatar

Be careful not to cache pages which might be common to users with different timezones. Or use javascript to change the times on the client side.

@ryanb, can you please elaborate a bit more about the leaky before filter? It's convenient that time accepts a block so around filter fits in perfectly, but i was just curious about the leaky before filter comment.

Avatar

Hi Ryan,

There is a small issue with the caching mechanism you showed. If the user details is modified by another session , then the cache would not fetch the latest information. In short, there should be a way to invalidate this cache.

Avatar

I've corrected the show notes, thanks for letting us know!

Avatar

How to give size storage of tenant? Is it possible to check the actual size of the tenant through the Rails application? If so, can i get a detailed view such as how many size of tenant?

Any thoughts?

Avatar

Notice if you deploy to heroku now, you'll receive a mail said "The database contains 24,706 rows, exceeding the plan limit of 10,000"...

Avatar

still didn't found a way to do it, but the multi tenancy casts are a great help to succeed with my goals.

thanks so much to ryan for all the great episodes!

Avatar

@4awre
there are several ways, look at this:

for Devise:
https://github.com/plataformatec/devise/wiki/How-To:--Isolate-users-to-log-into-a-single-subdomain

http://blog.plataformatec.com.br/tag/subdomain/

http://blog.plataformatec.com.br/tag/subdomain/

Authorisation:
and you should take a look to authorisation from scratch. it works perfectly for me,
but i'm still very interested to see what cancan2 will bring :)

Avatar

great video, thanks!
One question though, how to display a standard message for "no results found"?

Avatar

This doesn't seem to work if you are already redefining the logger.
I use the following in the configuration file in order to cycle log files...

ruby
  require 'active_support/core_ext/numeric/bytes'
  config.logger = Logger.new(config.paths['log'].first, 2, 5.megabytes)
  config.logger.level = Logger::DEBUG

Either of the following two lines will cause errors, the first on webrick startup the second on the first call to the logger

ruby
  config.logger.log_tags = [:remote_ip, lambda { |req| Time.now}]
  config.log_tags = [:remote_ip, lambda { |req| Time.now}]

Seems the 'log_tags' method isn't defined

Avatar

Hi, when I try to call the send_password_reset I get this error:

ruby
Validation failed: Password can't be blank, Password is too short (minimum is 6 characters), Password confirmation can't be blank

Does anyone can help me, please?

Avatar

I'm trying to set up Sidekiq to work with Monit, but it seems to be needing to cd to current_path before executing bundle exec. Does anyone know how to tell Monit to cd to my app's directory before executing the start command? The commands in Monit also fail if I try to start them without /usr/bin/env

check process sidekiq
  with pidfile <%= current_path %>/tmp/pids/sidekiq.pid
  start program = "/usr/bin/env bundle exec sidekiq -C <%= current_path %>/config/sidekiq.yml -P <%= current_path %>/tmp/pids/sidekiq.pid" as uid deployer and gid admin with timeout 90 seconds
  stop program = "/usr/bin/env kill -s INT `cat <%= current_path %>/tmp/pids/sidekiq.pid`" as uid deployer and gid admin with timeout 90 seconds
  if totalmem is greater than 800 MB for 2 cycles then restart # eating up memory?
  group sidekiq
Avatar

I figured it out. in my nginx.conf file, I didn't change "blog" to "myapp" in the upstream command - but i had done so in the second place in that file that needed editing. Thanks again, Ryan!!

Avatar

@cpuguy83 You're absolutely right, that's one big advantage of clint-side MVC.'s

But after spending a year battling with Backbone, I'm just not a big fan. Backbone and javascript is a lot of fun, but I find sticking to mainly Ruby/Rails to be where I'm most productive.

By sticking with mostly Rails, you can avoid having to test/debug lots of JS, devising a strategy for sharing views between Rails and JS, logic duplication in Backbone models and Rails models, etc.

I think caching + utilizing Rails UJS + RJS (rails js templates) is a winning combo for many apps. That's why cache digests is sweet :-)

Avatar

The screencast adn everyone's comments have really helped me through setting up the server. I feel a lot better about server setup, now.

Everything is working great - went through the whole screencast - the only difference for me is that I'm using mysql. Mysql is installed properly, and upon deploy, running the db migrations works and results in the tables being created in the database. So I know it's connected properly.

However, when I go to one of the URLs for that scaffolding (for me it was /users), I'm getting a "we're sorry, something went wrong" error.

The routes work perfectly locally. Not sure what the issues is because MySQL seems to be working and connected based on the migrations?

If anyone has any suggestions (or pointers to help debug these server errors), i would very much appreciate them.

Avatar

Once again your provide timely info. Thanks!
I have a project with two sister schools. The sites are almost identical except for some small cosmetic changes, and they have different dynamic content. The users of each site should be able to login to the other site (but of course privileged accounts should only be privileged in the home site). I can see how to implement this based on your Railscast.
My question is can this be done with two domains instead of sub-domains? I would like to have siteA.com and siteB.com instead of siteA.domain.com and siteB.domain.com. Is this possible? How would I start? Or should I just maintain two sites and have some sort of joint login system (and how would I do that?)

Avatar

What to force cache to expire? for example when the list of items are updated?

Avatar

There is a typo in the show notes, it's missing the underscore:

rake refinery:override view=refinery/_head

Avatar

One last possible thing might be a way to restrict users to specific tenants. So that a use can only log into one tenant. Maybe with some kind of authorizaton system like cancan??

Avatar

Something's not working. Heroku outputs the "looking for faye" messages, but not my messages. Have followed your debug tips, but they don't help to solve the problem. Are you sure, the port
9292 on heroku is correct? I get:

Errno::ECONNREFUSED (Connection refused - connect(2)):
app/controllers/messages_controller.rb:8:in `create

When I leave the port number off, there is no failure message anymore. (Still doesn't work though…)

Avatar

Thanks Ryan, great as usual! I wonder if Heroku or Appfog have any issues around using Postgres Schemas e.g. limitations on the dev databases therein? I used scopes 2 years ago when I last did a multi-tenant app but at the time I wanted to make use of Schemas I have to say - it seems less fussy and more secure plus less likely to forget to scope data etc. Maybe I'll migrate the old site to this method (only 3 subdomains including www) if Heroku supports it...

Avatar

Hi guys, It seems that Capistrano has in fact now removed the cap deploy:web:[action] tasks. Being that I'm very new to Capistrano, could anyone point me to some info on how to get that functionality back?

Avatar

Hi Luke,

This is actually the problem caching is trying to solve. Instead of reading from your DB and rendering partials rails is smart enough to look for a cached file, which, if it exists, will be used for the response.

Only if information critical for the request has changed, will a new version be created.

Hope this helps.

Avatar

Nice, thanks Mark. Does anyone else have any other examples?

Avatar

Another good gem to check out is Settingslogic. While Figaro is easier to set up, Settingslogic allows nested configurations which feels for cleaner code.

Avatar

Have you managed to solve this problem Faraz? I'm having the same issue..

Avatar

Thanks Ryan!! this was exceptionally useful. The fact that you took the time to figure out how to this gem run server side was just great.

It would be good to see a follow up casts using custom css formatting and other interesting tricks. (ie how to handle timeouts, ignoring searching on specific columns).

But what is really useful in the casts are the gems we never heard of used in ways we did not realize were possible. ie charting was a great example

Avatar

Never mind I figured it out :)

Change:

$("#products").html("<%= escape_javascript(render("products")) %>");

To:

$("#products").hide();
$("#products").html("<%= escape_javascript(render("products")) %>").fadeIn(500);

Avatar

Had a sneaky error on the last step with the re-direct. All the parameters updated my record properly, but got the following error: wrong number of arguments (1 for 0), _steps_controller.rb:57:in `redirect_to_finish_wizard'.

Using the Finish Wizard Path definition at: https://github.com/schneems/wicked it worked fine.

Thanks for a great tutorial!!

Avatar

I kept getting this when I tried to update my password:
ArgumentError in PasswordResetsController#update
comparison of Date with ActiveSupport::TimeWithZone failed

Fixed it by doing this:

password_resets_controller.rb
if @user.password_reset_sent_at < 2.hours.ago.to_date
Avatar

it's even better

orders.where(...).group(...).sum(:price)

unless I'm missing something important ^^

Avatar

If you are interested in getting private_pub running on Heroku, consider heroku_private_pub on Github. Just configure and push it. And the readme includes some handy debugging tips at the end.

Avatar

@chewmanfoo, I'm not sure but I'm guessing you're missing the css style and instantiating the behavior:

ruby
f.input :change_set_revisions, :as => :select, :collection => ChangeSetRevision.all.sort_by(&:name).reverse, :input_html => { :class => "chzn-select" }

And then instantiate add the behavior to elements with the .chzn-select css class:

javascript
$(".chzn-select").chosen();
Avatar

Don't forget that if you are going to use something like this in a secure environment (SSL) then you should get a wildcard certificate. Otherwise your clients will get certificate errors.

Avatar

Can someone explain how to get this working with mongoid?

many many thanks

Avatar

anyone know what formtastic needs in the form to replace the collection_select for the first example (using Chosen). I have this:

f.input :change_set_revisions, :as => :select, :collection => ChangeSetRevision.all.sort_by(&:name).reverse

but it sticks with the normal multiple-select drop-down box. I do not get the javascript decoration.

Avatar

The pdf mime type is added by default in Rails 3.2: http://edgeguides.rubyonrails.org/3_2_release_notes.html

So you no longer need to tell Rails about the PDF MIME type with the following line:Mime::Type.register "application/pdf", :pdf

Avatar

Forgive a newbie. In ryans examples where do you put that code?

Avatar

You either have to change the Facebook Site URL or you hosts file. To edit your hosts file when you want to work on your app locally:

sudo nano /etc/hosts

Add:

127.0.0.1 www.yourdomain.com

Save the hosts file

Restart your browser.

Restart rails using port 80:
rvmsudo rails s -p 80

Now when you go to www.yourdomain.com it should be hitting your local dev machine.