RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I don't know any more about MongoDB other than what's covered here. How would I decide whether it's relevant to my app and I should go learn more? Right now my app uses MySQL.

Once I become knowledgeable about MongoDB, how would I decide whether using MongoDB is the right choice?

Thanks!

Avatar

I have the same problem with you .

Avatar

I get a ReferenceError: event is not defined loading the page as soon as I add the code to implement "remove" in javascript. From Firebug:

(function() {

jQuery(function() {
$('form').on('click', '.remove_fields', function(event) {});
$(this).prev('input[type=hidden]').val('1');
$(this).closest('fieldset').hide();
return event.preventDefault();
});

}).call(this);

Anyone have any idea what's going on? Any help appreciated.

Avatar

Error after installing bootstrap, can someone help ps? I'm using Rails 3.2.9, therubyracer already installed:

LoadError in Products#index

Showing C:/.../store/app/views/layouts/application.html.erb where line #5 raised:

cannot load such file -- less
(in C:/.../store/app/assets/stylesheets/bootstrap_and_overrides.css.less)
Extracted source (around line #5):

4: Store
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>

Avatar

Please help!! I have followed the tutorial verbatim but the published_on date is not showing up in calendar view. Unless i put this code in articles_controller.rb and it only shows entries for current days only. @articles_by_date = Article.all.group_by {|i| i.created_at.to_date}.
Is there a way to show published_on date for current/past and future dates also?

Avatar

There is also a gem called CsvRecord that serves as a persistance layer between csv files and Ruby classes, either importing or exporting. It also implements validation and associations and it can be used alongside ActiveRecord.

https://github.com/lukasalexandre/csv_record

Avatar

Unlike AASM and Workflow, state_machine supports multiple state machines at same object/class.

Avatar

simply remove the following method, if you want to use alias_method. or remove the alias_method call

ruby
def linkedin
  user = User.from_omniauth(request.env["omniauth.auth"])
  if user.persisted?
    sign_in_and_redirect user
  else
    session["devise.user_attributes"] = user.attributes
    redirect_to new_user_registration_url
  end
end
Avatar

Why don't you use the find or create syntax in the product model instead of doing find || new ?

Avatar

It would be interesting to see some data on how much Tubolinks speeds up a real site.

Turbolinks Test seems to run locally, where the request time is about 20ms (on your computer). But in real use it is about 0.5 to 1 sec.

Avatar

This solution is not the best idea for the situation where you have large csv files (like 40k+ rows)

First of all it will parse large files synchronously - which means you have to wait for the webserver response till parsing is done

The second major problem is that each row is inserted in separate transaction - which is obviously slow as hell

So,as for me, I would not recommend to use this technic for large files

One more thing - if gem you using for CSV parsing loads entire file into memory - this memory won't be freed up after conversion (it is one of the major Ruby's problems)

Avatar

Great example, how would we accommodate custom mapping vs static header mapping?

Avatar

Someone mentioned this already, but it wasn't clear until I found this StackOverFlow answer. To sign_out, you must specify the method as 'delete'.

ruby
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>.

See http://stackoverflow.com/a/6557627/1316635

Avatar

Why do require 'csv' in application.rb and not in product.rb where it's actually used?

Avatar

Thanks a lot Ryan for this and the other Railscasts that you have done on deployment.

On Capistrano's from-the-beginning wiki, there is a section on avoiding deploy:cold which says

First of all, deploy:cold was a bad idea. It attempted to do what I have described in this tutorial, but without enough opinions, and without enough options for configuration. I’ve come to the conclusion that setting up a new app on a new machine is not something that can be generically automated.

Ryan, would you suggest to avoid deploy:cold?

Avatar

Update. I went a little farther into the Screencast to see if the code would eventually work. After failing on the very first import, I spit out a CSV file with the IDs, and all columns and with the following code, it works now.

def self.import(file)
  CSV.foreach(file.path, headers: true) do |row|
    document = find_by_id(row["id"]) || new
    document.attributes = row.to_hash.slice(*accessible_attributes)
    document.save!
  end
end
Avatar

I ran into a problem immediately, and from what I can tell it is because I am using a pg_search enabled Document model I am trying to import. I also have another form_tag that I use to search Documents on the index page. Everytime I try to import I am getting.

A ActiveRecord::StatementInvalid occurred in documents#import:
PG::Error: ERROR:  relation "pg_search_documents" does not exist
LINE 5: WHERE a.attrelid = '"pg_search_documents"'::reg...

If I remove the include PgSearch section from the Document model the CSV import works perfectly fine. How can I resolve this issue?


The relevant portion from Document.rb:

include PgSearch
  pg_search_scope :search, :against => [:title],
    :using => {:tsearch => {:dictionary => "english", :prefix => true}}
Avatar

You can also add another newline between the object declaration and the call to createToken.

processCard: ->
  card =
    {number: $('#card_number').val(),
    cvc: $('#card_code').val(),
    expMonth: $('#card_month').val(),
    expYear: $('#card_year').val()}

  Stripe.createToken(card, subscription.handleStripeResponse)
Avatar

It sounds like you don't have your CORS setup right (or at all). Check that you're using the right Origin Domain (as specified in the CORS policy).

Also you should use https://s3.amazonaws.com/xyz instead as you'll get invalid certs for https://xyz.s3.amazonaws.com.

Avatar

Have sometimes problem with "Cannot allocate memory" when mail sending or image uploading... but I have 1 Gb ram for not high loaded app :(

Avatar

You have this:
<%= link_to "Logout", destroy_user_session_path, method: :delete%>

Try this instead:
<%= link_to "Logout", destroy_user_session_path, method: :delete %>

You might want to use stackoverflow for help with these questions in the future. You'll probably get a faster and more helpful response.

Avatar

Hi there, how can i get load_and_authorize_resource working with this from cancan?

Avatar

attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
attr_accessible :crop_x, :crop_y, :crop_w, :crop_h

Avatar

+1 This saved my day...I tried using the store_accessor that activerecord provides and it didn't work. This worked perfectly!

Avatar

I got the following error: /blog/app/views/layouts/application.html.erb:16: syntax error, unexpected ':', expecting ')'
...royuser_session_path, method: :delete);@output_buffer.safe...

basically -- the app doesn't like the following line:
<%= link_to "Logout", destroy_user_session_path, method: :delete%>

specifically, does not like "method: :delete" -- remove those, it loads but then errors because the controller isn't found.

Avatar

Hi,
just wondering if someone might be able to answer this?

1) how to prevent certain file type from being uploaded to AWS S3?
For example, i don't want user to upload video file at all, how to prevent it?

2) Is there a way in AWS S3 upload script to stop the files upload from triggering if each user is limit to 5 files upload per user?

Thanks for the help :- )

Avatar

I would also recommend the mongoid-ancestry gem for Mongoid based Rails apps.

Avatar

It would be cool, but maybe you have to make sure the user changes his email address, the name, and so.
Else, if users need to confirm their email addresses in the "normal signup" (for example), then you are leaving an open back door.

Avatar

How do you replace the ugly id and replace it with a seo friendly url?. lol it's at the end of the video, thank you Ryan for always thinking about that!

Avatar

Just subscribed because I needed to do this exact task. I'm not disappointed I signed up! Good episode thanks!

Avatar

This is a great way to get the "other" side of a polymorphic has_many.

Avatar

I suppose that if you can decide the value of the evaluation, you could use this gem for rating 1-5 stars right? or would it be crazy?

Avatar

awesome you're bringing more attention to action_missing...it is the magic by which my gem blue_velvet works.

Avatar

Was noticing that this was not doing anything to standardize the capitalizations so therefore tagname and Tagname are two different things in this implementation, in order to fix this I simply used a before_save to titleize the names with this:

ruby
before_save :titleize

def titleize
  self.name = self.name.titleize
end

Pretty simple but assigning of the name threw me for a loop for a minute. Great cast!

Avatar

Or you can use pure CSS to highlight current page based on nested classes.

E.g, body.products > nav.item

Highlight nav.item.products when the body is also products.

Avatar

The RSS at the top right of the page will give you a personalised link containing the pro episodes.

http://railscasts.com/subscriptions/...../episodes.rss

Avatar

This is great, however how can I maintain the non subdomain portion?

I'd like that to exist still as a master backend?

Avatar

Hello!

Does anybody know if Travis CI will run this type of tests? Having a lot of trouble finding info. on that particular subject.

Avatar

Looks like a good idea, I'll use it in my future projects!

Avatar

Now I may have missed something obvious, but the one area that seems to be missing is securing the Tenant model.

You only want a none authenticated person to sign up and create a new tenant
You want an existing tenant to only edit, update, and destroy, and only their own account
And then you want the admin to do anything, but that is a special case for many things

So I guess this is all going to be custom code within the controller (ie force the id in edit, update, and destroy. Only allow new and create if current_id does not exist)

thoughts?

Avatar

Actually when you play with such DBs there is no need for STI cause there are no tables. And class inheritance becomes really good and natural approach then.

Avatar

I've build a solution:

http://stackoverflow.com/questions/13660058/ruby-on-rails-js-input-token-an-issue-when-validation-fails

Hope it helps to someone, or spark some ideas on other implementations. :)

Avatar

And if you use fragment caching, you should highlight current page in menu using javascript.

Avatar

Shouldn't be the line in the notes

puts ArticlesController.ancestors - ArticlesController.included_methods

changed to

puts ArticlesController.ancestors - ArticlesController.included_modules

?

Avatar

Found it selectable_column inside the index do block

Avatar

Hey does anyone know how to show the selection toggle next to each row for batch actions when using the custom table columns.

This is there by default but disappears as soon as we customize. I'm not able to find it in the documentation.