RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

checkout http://joshdmiller.github.io/ng-boilerplate/#/home

it has good examples of how to do tests. It doesn't take much to customize to get to work with something similar to what is suggested in this screencast.

Ignore the rails part
angular does not depend on rails.
just search for angular testing or angular karma tests

Avatar

In case it might help someone, in Rails 4.0.0/Ruby 2.0, I was getting this error:
private method 'h' called for #<#Class:0x00000003dcd130:0x000000037ef538>

Instead of delegating h to the view_context, I called it directly like this:

ruby
def data
  products.map do |product|
    [
      link_to(product.name, product),
      ERB::Util.h(product.category),
      ERB::Util.h(product.released_on.strftime("%B %e, %Y")),
      number_to_currency(product.price)
    ]
  end
Avatar

Use *= stub mercury.css and //= stub mercury.js to exclude Mercury by default then include it explicitly on editable pages.

This has an advantage over removing the require_tree line in that all your javascript and css files will still be included without having to explicitly add them.

This is new to Sprockets 2.2.0 and up, I believe.

Avatar

OK, I fixed it by changing all my eventcategory stuff over to eventcat to keep the naming less likely to get mixed up.

Avatar

Tire might be retired but this Railscast has dated well. Everything works in Rails 3.2.14.

elasticsearch-ruby doesn't appear to be finished and isn't as well documented.

See Karel Minarik's commit here for some improvements on Ryan's code - https://github.com/karmi/tire/pull/131

Avatar

I am just running localhost via rails server, and somehow I can't get any of the subdomains to load any pages. So lets just say if I use user1.example.com:3000 (i run my development on a remote server), the page just doesn't load.

And example.com:3000 works. I've read multiple tutorials, but wasn't able to find an answer to this.

I've also tried this on my windows PC, and have set these in host file 127.0.0.1 subdomain1.localhost.local company.blog.local personal.blog.local, but this doesn't work either.

Pulling my hair out for this. Any help is appreciated!

Avatar

Hi, I was wondering if the field in the translation table must be the same as the one in the model. Say I want to translate description_en and would wish to have a field description_se on translation table. And further be able to access both attributes from rails admin.

Avatar

"Match" has been deprecated in Rails 4 and has to be replaced with "Get".

Avatar

Capistrano has just been updated to 3.0! Any advice?

Avatar

I replaced the salt with:

def self.authenticate(email, password)
user = find_by_email(email)
if user && BCrypt::Password.new(user.encrypted_password)==password
user
else
nil
end
end

def encrypt_password
if password.present?
self.encrypted_password = BCrypt::Password.create(password)
end
end

Avatar

You'll want to set the credentials in the environment as shown in the episode, so you can access them using ENV (and so the actual credentials aren't in the code).

As for how to manage the ENV variables, check out http://railscasts.com/episodes/85-yaml-configuration-revised or this gem https://github.com/laserlemon/figaro

Avatar

What's the best way to handle step-specific javascript code?

Avatar

I'm trying this on heroku, but it seems the pub/sub doesn't work . Does anyone use this(ActionController::Live, puma, redis) on heroku. I want some advice.

Avatar

I'm using Ruby 2.0 and Rails 3.2.8 and I can't seem to get the simple has_many through part working.
In my Event model

ruby
  attr_accessible :address1, :city, :country, :description, :enddate, :eventname, :startdate, :state, :status, :url, :zip, :eventcategory_ids
  has_many :categorizations
  has_many :categorizations
  has_many :event_categories, through: :categorizations 

In my Eventcategory model

ruby
  attr_accessible :description, :eventcategory, :event_id
  has_many :categorizations
  has_many :events, through: :categorizations 

In my Categorization model

ruby
  attr_accessible :created_at, :created_by, :event_id, :eventcategory_id
  belongs_to :event
  belongs_to :eventcategory

The tables are all there for all three models.

When I run: e = Event.first in the console it gets me my first event.
Then I run: e.eventcategory_ids I get: NoMethodError: undefined method 'eventcategory_ids' for #<Event:0x00000002b7d660>

I figure that has to work before any of the rest of the stuff from this screencast will work for me... right? Am I missing something here?

Avatar

In Firefox only.
http://localhost:3000/user_steps/%2E%2F%2E%2E%2F%2E%2E%2Fconfig%2Fdatabase%2Eyml
show database.yml

http://localhost:3000/user_steps/%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2F%2E%2E%2Fetc%2Ffstab
show /etc/fstab

...

Avatar

Ryan. On behalf of all beginners I am begging you PLEASE stop using Coffeescript. It is hard enough that we have rush to master several techniques simultaneously, people keep overcomplicating stuff which is already hard enough with things like Coffee. Please!!!

Avatar

Tire has been retired. Read the explanation here:

https://github.com/karmi/retire

Looks like there is a replacement:

https://github.com/elasticsearch/elasticsearch-ruby

Would love a Railscast for this, especially since this Tire railscast is almost 2 years old.

Avatar

Thank you.

With Rails 4 depreciating Relation#update_all, your solution worked.

Avatar

Rails 4

DEPRECATION WARNING: Relation#update_all with conditions is deprecated. Please use Item.where(color: 'red').update_all(...) rather than Item.update_all(..., color: 'red').
Avatar

Hi all,

I am trying to reproduce this approach using simple_form, but I am not sure how to recreate the check boxes using simple_form with all the features Ryan covered in this screencast.
Has anyone done this earlier?

Appreciate the help.

Xiao

Avatar

same here. tried to download in itunes and says: "This movie requires QuickTime, which is not supported by this version of iTunes."

Avatar

Use new_user_session_url_path instead.

Avatar

I am getting this error as well Daniel Gaeta. Not using Sorcery, but I am using Doorkeeper and OmniAuth.

Avatar

If you're going to session, why not store the whole thing in session, and then add it to their account upon sign up?

No guest accounts needed.

Avatar

Same here, not working for me either.

Avatar

[{:code=>"10478", :messages=>["Invalid Data", "Recurring payments profile description must be provided if the billing agreement type is recurring payments."]}]

what does this mean if i get this error

Avatar

I do not want to use my AWS credentials to use directly in carrierwave.rb file as pushing it to Github will make it public. Is there a way to create a private file and call the credentials from there?

Avatar

shorthand...

Gemfile
gem 'mongoid', github: 'mongoid/mongoid'
Avatar

uploaded file disappears if validation fails. Is there anyway to handle this as It is not user friendly to ask user to upload file every time validation fails.

Avatar

client_side_validations isn't maintained anymore. Does anyone knows a alternative?

Avatar

I was getting this error because my app was in sandbox mode and I was using real users. Once I created test users and use them instead, it started working.

Avatar

The Redis subscription keeps blocking my req-res cycle and my browser seems to keep loading for ever. Does any one has this issue? Please help.

Avatar

Just wondering Rajeev if you found a solution to this? Thanks

Avatar

For future reference: This happens because the ENV["OAUTH_ID"] ENV["OAUTH_SECRET"] aren't set.

Avatar

Thank you!! I had the same problem.

Avatar

Great cast.
I don't really like to override the .json mime type to always respond with the datatable-formatted JSON
I suggest aliasing the "text/json" mime type to a new type called something like "datatable"
This leaves .json still functioning as it would

initializers/mime_types.rb
Mime::Type.register_alias "text/json", :datatable
products_controller.rb
respond_to do |format|
  format.html
  format.json       { render json: @products }
  format.datatable  { render json: ProductsDatatable.new(view_context) }
end
views/products/index.html.erb
data-source="<%= products_url(format: "datatable") %>"
Avatar

I ran into the problem with Mongoid that Mongodb stores the "id" as "_id":{"$oid":"524d74d31c187026b4000001"}. So not only the tag is different, also the id is nested.

What made it work for me is parsing the instance. See below.

class YourApp.Models.YourModel extends Backbone.Model

..parse: (your_model) ->
....your_model.id = your_model._id['$oid']
....your_model

(dots are white spaces)
This is important, because the "id" is needed to navigate to update instead of create, etc.

Hope this is helpful to anyone. If there is a better approach, Lmk. Coffee, JS and BB are new to me ;-)

Avatar

Thanks Solomon for your solution ! It works great!
I'd like to use your solution as a scope (because I'd like to make a search not based only on tags).
The problem is that the "all" method breaks chaining scope.

I tried to make a scope like this, but doesn't work (not the expected result) :(

scope :tagged_with, lambda { |names|
joins(:taggings,:tags).where(tags: {name: names}).group('articles.id').having(['COUNT(*) >= ?', names.length])
}

Any idea ?

Avatar

And in anyone else has a similar issue, the solution was simple. I had tried already but not for all my hmts at the same time, so didn't get the right outcome. All you have to do is make an alias like this:

has_many: reader_persons, :through => :persons, :source => :person

def reader_tokens=(tokens)
self.reader_person_ids = Person.ids_from_tokens(tokens)
end

and similar for writer_persons

Avatar

Dude! You rock! Thanks for the info.

Avatar

If you are using these recipes and get an error on

run %q{eval "$(rbenv init -)"}

executing "eval \"$(rbenv init -)\"" servers: ["ip_removed"] [ip_removed] executing command ** 
[out :: ip_removed] sh: 2: /home/deployer/.rbenv/libexec/../completions/rbenv.bash: ** 
[out :: ip_removed] Syntax error: "(" unexpected (expecting "}") ** 
[out :: ip_removed] command finished in 427ms failed: "sh -c 'eval \"$(rbenv init -)\"'" on ip_removed

You can just remove that line and replace the PATH line above with:

run %q{export PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"}

See:
Syntax error running rbenv init
and
Running rbenv from capistrano

Avatar

Thanks for mentioning that. It's useful even over a year later...

Avatar

Hi,
a newbie question. Got two models Job and Company. A company has_many jobs and each job belongs_to company. Building a form for Job which has collection select that allows user to select already existing company or create one with three fields i.e. name, info, and logo. So far all i have seen is accepts_nested_attributes_for being used in the form of model with has_many relationship and not belongs_to. I saw ryans create model through textfield railscast and this one but couldn't figure out which approach to go for. I like the create model through textfield but how to create three fields rather than one. Any suggestion would be highly appreaciated.

Avatar

hi, were you able to do that? if so how?

Avatar

Hi,

I created 2 admin, based on the user role it will be navigated.

I want to create multiple domains. How to make the admin can create domain and populate the views accordingly.