RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi, i am new with ruby on rails.
I have this problem:

LoadError in Products#index

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

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

This make all like in the video. Help please!!!

Avatar

I've done this. I was having difficult getting templates to work, probably with haml, I don't really know, but the solution wasn't difficult once you realize there's no magic happening in the tmpl function.

In place of data.context = $(tmpl("template-upload", file)) pass file to your own function that marks up some html and set it to data.context. i.e. data.context = createNewStatusbarElement(file).

That function can build up the html element for the status bar from hardcoded html in strings, jquery methods, handlebars templates, or - as I've done - by cloning a hidden element (basically a poor-man's template).

Avatar

Thanks Ryan, exactly the right episode at the right time :)

One note on using curl. It seem easy and nice to simply generate the static pages via "curl http://localhost:3000/errors/404 > public/404.html".

But beware that you generate them under the development environment but serves them in production. At least when they are checked in and deployed to production.

Your pages may contain stuff that should only be visible in development mode and not on staging or production.

So you may need to run the curl command on production to get the correct pages. That can be done manually after each deployment but that's cumbersome.

One can add a capistrano recipes that runs after deploy:restart (when the app is up using the maybe new layout). But then you great the pages whenever you restart the app.

And with static pages you cannot serve different pages for different context. For example a signed in user will get a 404 page without his user menu (preferences, account, ...) and
maybe without the logout button. That can be ok in your case but should be considered.

If you are fine with static pages you may generate them outside the controller via a rake tasks and run that task on every deployment via after "deploy:create_symlink", "deploy:error_pages:create"

We tried this but now using your solution via the ErrorsController.

Thanks!

Avatar

I guess, you might have added the GoogleCalendars support.
I am facing problem in working out the google calender, event insertion using OmniAuth on google oAuth v3

Avatar

Ryan,

Here's a suggestion for your railscasts that deal with JSON responses. Make the server reaponse automatically pretty-print the JSON so that it's easier to visually follow.

I've found this neat rack middleware trick:
http://stackoverflow.com/a/13029297/1148455

Avatar

Thanks for mentioning this. I ran into the exact same thing.

Avatar

Has anyone found a good way to test this with RSpec?

Avatar

Hello there,

This episode is great and helpful,but what if I need additional fields for storing like tag description? Any idea?

Avatar

Not sure if I did something wrong or if Rails 4 changed, but I ran through this episode using Rails 4 beta. The link in the view to point to page_path("about") worked fine if I wanted http://site/pages/about as my link but did not change to just http://site/about even after changing the route.

I wound up making that page_path["about"] and it seemed to work correctly. Just dropping this here if anyone else encounters it.

Avatar

Following the instructions from this screencast, I was able to configure the gem to work on my local machine (a Mac) perfectly fine. However, deploying the application via capistrano to a Linux box, running the app with unicorn doesn't appear to be working. My unicorn.log contains the following error:

E, [2013-04-24T15:20:23.211288 #6163] ERROR -- : uninitialized constant ExceptionNotifier (NameError)
/path/to/app/releases/20130424201053/config/environments/production.rb:80:in `block in '

even though the gem is installed. I can't figure out how to load the library. Any help?

Avatar

@tpy,

Just in case you were still wondering, Rails creates these IDs when you use the <%= form_for ... %> helper. It knows that you're creating a new record so it defaults to a form ID of "new_model". It does the same thing for the IDs for various inputs.

Avatar

Actually had this problem in a project a while back. Ended up using a UUID as the property's hash key, but using a display_name when displaying them, allowing the field names to change without breaking the rest of it. It was complicated, though, and I'm not sure doing so would work well with Hstore. It did add a few extra layers of abstraction and wasn't very fun to work with. @phillyslick also makes a good point that deleting fields doesn't delete the data from the properties hash. The only way we found to work around that was to update all the items of a certain type if the type changed.

This is a great cast, but in my experience doing this kind of thing can bring you down a pretty slippery slope if the users aren't warned of the consequences. With great flexibility comes great responsibility, and diligence and well tested rake tasks should be built into the system.

Avatar

Nice episode, but it would be beneficial to add something like response.status = request.path[1..-1] to make the status code carry over (if anyone knows of a nicer way to do this, speak up).

Otherwise, the error pages will all have a status of 200 OK since the error controller itself responded normally.

Avatar

Hi Jesus H. Did you ever figure this out? I'm having the exact same issue. Thanks!

Avatar

+1 for counter_culture. This really should be how Rails works by default. In my experience the need to have multiple counter cache columns (goals, completed goals - books, books read) is the norm rather than the exception and this gem allows that and much more.

Avatar

authors << {id: "<<<#{query}>>>", name: "New: \"#{query}\""}

Removing the brackets makes it work.

Avatar

Thanks for all the railscasts.

I have been thinking to change an existing app of mine to a single page app. Planning to use either backbone, angular or ember. Saw the railscasts on all three of them and I understood how to get them to rails.

I am sure that each of these have their own pros and cons depending on the situation. It would really be nice if you have a railscast that can elaborate on the situations where one them would be better than others.

Avatar

Has anyone figure this out?

For example, in my app I have a genre field, and if, say "Punk Rock" is already an option, and someone wants to just add "Punk", "Punk Rock" shows up in the dropdown and there is no option to add just "Punk".

Seems that If you want to add anything that is already included in another name you won't be able to.

Avatar

As much as I love Ryan and all the Railscasts, this one is a bit confusing, for this reason:

When Ryan talks about "reputation_value_for" (now "reputation_for") as giving him the "total number of votes," it is in fact giving him the SUM OF THE VOTE VALUES. So, if one is looking for the actual total number of votes, regardless of vote value, the returned value is incorrect.

In fact, as far as I can tell, there is no generic way to get the total number of votes on a model without assigning a constant "1" to a vote tally value and using reputation_for(:vote_tally). So, in order to end up with:

78% of 281 voters like this Haiku. You like it, too.

...there is a need to add a THIRD reputation to get the count of ReputationSystem::Evaluations on the Haiku model, since we need to use:

has_reputation :votes, source: :user, aggregated_by: :sum
has_reputation :avg_vote, source: :user, aggregated_by: :average

...in order to get the user's vote (assigned as 1 = like or 0 = unlike) as well as the average vote. So we add:

has_reputation :vote_tally, source: :user, aggregated_by: :sum

Then, in the vote action in the controller:

v_value = params[:type] == "up" ? 1 : 0
@haiku.add_or_update_evaluation(:votes, v_value, current_user)
@haiku.add_or_update_evaluation(:avg_vote, v_value, current_user)
@haiku.add_or_update_evaluation(:vote_tally, "1", current_user)

If there's an easier way to get the total number of votes on a model, I'd love to hear about it.

Avatar

I had the same error. I am using company names instead of countries. All of my companies have a space in the name. Was wondering if you possibly found a fix.

Avatar

On REVISION: 12 it's not needed anymore. obj.deleteRecord() would suffice.

Avatar

hi, great! I am trying to figure out how to get the right syntax highlighting for unicorn_init.erb as shown in the screencast?

Avatar

when i try to search the words which has special characters like(computer & laptops,compuers)and plural word searching is also became problem for me using sunspot.kindly anyone help me to solve this issue.

thanks in advance

Avatar

Thank you, Ryan.
I got a syntax error with tokenInput and Rails 3.2.13, but fortunately fixed it by myself.
I guess that the new version of CoffeeScript compiler in Rails caused it.

What I got was

SyntaxError: unexpected INDENT

The solution is simple.
Just add "," after '/tags.json' in books.js.coffee.

books.js.coffee
$ -> 
  $('#book_author_tokens').tokenInput('/tags.json',
    theme: 'facebook'
    prePopulate: $('#book_author_tokens').data('load')
  )
Avatar

Can someone please help me - very desperate, will pay!
My very simple Rails App has a Model with two methods:

:From :To

I use the awesome (Google Maps API) powered address-rails-picker app for the :to and :from in the form to automplete any location the user types in.

I do however have trouble in writing a validation that forces the user to choose an autocomplete location instead of writing any gibberish the user wants.

Would the Token Input help here by limiting it to one? I don't wan the Facebook look though with the X etc.

Avatar

Thanks Michael Hawkins. That comment put an end to my misery.

Avatar

Just want to point out the massive acronym typo in the description.
It's WYSIWYG as in "woh-zee-wig". What You See Is What You Get.

I can't for the life of me figure out what "WISYIWYG" could stand for...
Wild Industrial Skeletons. You and I Will Yell Greatly?

Avatar

Oh Hey James! Haha. I tend to agree by the way, although lately I have my doubts on JBuilder's performance. But I might be hallucinating. Need to benchmark.

Avatar

This is certainly an area of my apps that needs some TLC. Thanks!

Avatar

Ok. Found it!

html
<a href="#" {{action removeItem this}}>x</a>
coffeescript
Raffler.EntriesController = Ember.ArrayController.extend
  # include the following method.
  removeItem: (obj) ->
    obj.get('content').deleteRecord()
    @store.commit()

My issue was that I was not calling 'deleteRecord()' on the 'content'.

Avatar

Any progress in how to sort column data from associated tables using server side processing?

ruby
class Workshop < ActiveRecord::Base
  belongs_to :location, :class_name => 'Location'
end

class Location < ActiveRecord::Base
  has_many :workshops
  attr_accessible :name,
end

Records are associated by id ( workshop.id = location_id)

On the Workshop datatable class, the information displayed is the location_name

ruby
class WorkshopsDatatable

 def data
    workshops.map do |workshop|
      {
        id:           workshop.id,
        location:     workshop.location_name,
      }
    end
end

I would like to be able to sort the location column by location_name and not by location_id.

Avatar

I have the same scenarios with many to many categories. I have found difficulty with update method on product. Any ideas to help?

Avatar

What is the proper way to delete an Entry?

Avatar

Problem got fixed using add this line in top of ~/.bashrc on remote server.

if [ -d $HOME/.rvm ]; then
  export PATH="$HOME/.rvm/bin:$PATH"
  eval "$(rvm init -)"
fi

Assuming that i am using rvm in my remote as well as in my local computer.

Thanks Ryan

Avatar

Unfortunately I've been swamped with a ton of work and have not attempted to get it working yet.

If I get some free time this weekend I'll try and give the implementation a shot :)

Avatar

I am trying to deploy my rails app to Linode VPS but after i finished all steps when i did

xxx@xxxx-desktop:~/myrailsapp$ cap deploy:cold

i got following error:

failed: "sh -c 'cd /home/deployer/apps/myrailsapp/releases/20130422101521 && bundle install --gemfile /home/deployer/apps/myrailsapp/releases/20130422101521/Gemfile --path /home/deployer/apps/myrailsapp/shared/bundle --deployment --quiet --without development test'" on xxx.xxx.xxx.xxx

full log is below:

 xxx@xxx-desktop:~/myrailsapp$ cap deploy:cold
      * 2013-04-22 15:44:59 executing `deploy:cold'
      * 2013-04-22 15:44:59 executing `deploy:update'
     ** transaction: start
      * 2013-04-22 15:44:59 executing `deploy:update_code'
        updating the cached checkout on all servers
        executing locally: "git ls-remote git@bitbucket.org:myrailsapp/myrailsapp.git master"
        command finished in 5385ms
      * executing "if [ -d /home/deployer/apps/myrailsapp/shared/cached-copy ]; then cd /home/deployer/apps/myrailsapp/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 88641306c92790d13f95beb7a2826a072ab72df4 && git clean -q -d -x -f; else git clone -q git@bitbucket.org:myrailsapp/myrailsapp.git maste /home/deployer/apps/myrailsapp/shared/cached-copy && cd /home/deployer/apps/myrailsapp/shared/cached-copy && git checkout -q -b deploy 88641306c92790d13f95beb7a2826a072ab72df4; fi"
        servers: ["xxx.xxx.xxx.xxx"]
    Password: 
        [xxx.xxx.xxx.xxx] executing command
        command finished in 5786ms
        copying the cached version to /home/deployer/apps/myrailsapp/releases/20130422101521
      * executing "cp -RPp /home/deployer/apps/myrailsapp/shared/cached-copy /home/deployer/apps/myrailsapp/releases/20130422101521 && (echo 88641306c92790d13f95beb7a2826a072ab72df4 > /home/deployer/apps/myrailsapp/releases/20130422101521/REVISION)"
        servers: ["xxx.xxx.xxx.xxx"]
        [xxx.xxx.xxx.xxx] executing command
        command finished in 951ms
      * 2013-04-22 15:45:22 executing `deploy:finalize_update'
        triggering before callbacks for `deploy:finalize_update'
      * 2013-04-22 15:45:22 executing `deploy:assets:symlink'
      * executing "rm -rf /home/deployer/apps/myrailsapp/releases/20130422101521/public/assets && mkdir -p /home/deployer/apps/myrailsapp/releases/20130422101521/public && mkdir -p /home/deployer/apps/myrailsapp/shared/assets && ln -s /home/deployer/apps/myrailsapp/shared/assets /home/deployer/apps/myrailsapp/releases/20130422101521/public/assets"
        servers: ["xxx.xxx.xxx.xxx"]
        [xxx.xxx.xxx.xxx] executing command
        command finished in 993ms
      * 2013-04-22 15:45:23 executing `bundle:install'
      * executing "cd /home/deployer/apps/myrailsapp/releases/20130422101521 && bundle install --gemfile /home/deployer/apps/myrailsapp/releases/20130422101521/Gemfile --path /home/deployer/apps/myrailsapp/shared/bundle --deployment --quiet --without development test"
        servers: ["xxx.xxx.xxx.xxx"]
        [xxx.xxx.xxx.xxx] executing command
     ** [out :: xxx.xxx.xxx.xxx] ERROR: Gem bundler is not installed, run `gem install bundler` first.
        command finished in 974ms
    *** [deploy:update_code] rolling back
      * executing "rm -rf /home/deployer/apps/myrailsapp/releases/20130422101521; true"
        servers: ["xxx.xxx.xxx.xxx"]
        [xxx.xxx.xxx.xxx] executing command
        command finished in 971ms
    failed: "sh -c 'cd /home/deployer/apps/myrailsapp/releases/20130422101521 && bundle install --gemfile /home/deployer/apps/myrailsapp/releases/20130422101521/Gemfile --path /home/deployer/apps/myrailsapp/shared/bundle --deployment --quiet --without development test'" on xxx.xxx.xxx.xxx

I tried all the ways and update following in deploy.rb
require "bundler/capistrano"

but problem still unresolved,Anyone can help me?

Avatar

You're welcome! I certainly did not perceive your comment about typos as rude, and I can certainly imagine that some of these typos could certainly confuse beginners a great deal. I do not write the ASCIIcasts though ;-)

As a moderator I am happy with anyone who takes the time to report inconsistencies or flaws in the textual content on the site so that they can be corrected by one of the moderators, by doing so you make Railscasts a better place for everyone! I am glad this work is appreciated!

Avatar

Thanks, i have similar problem, now problem got fixed.

Avatar

Thanks @jeremydt by your solution my problem got fixed

Avatar

Hello

When i try to deploy VPS after running service nginx start command i got following error:

root@li356-76:~# service nginx start
 * Starting nginx nginx                                                                   nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

What should i do to fix this problem?

Avatar

Thanks for updating. Also hope my comment below about typos isn't rude. I realize that it takes extra work to add the ASCIIcasts and in the final analysis I find them very useful as I don't always want to rewatch a video. Your diligence in maintaining them is appreciated.