RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

how can i pass array in xAxis..

in view file
<% percentage_array = [1,2,3,4] %>
<%= hidden_field_tag('percentage_array', percentage_array) %>

and in javascript
xAxis: {
title:{text: "%age of student"},
categories: "#{percentage_array}",

   },

it does not work.All values of array shows only for first interval of chart. please help.

Avatar

Noob question. I'm confused about the first line in the new.js.erb file where he selects an element "#new_task". Where is this element located? I looked through the source code and couldn't find anything. Is there a Rails convention for this that I should be aware of?

Avatar

I just deploy this application to EC2 and got no errors but when I go and try to see the page using production.foo.com or the actual *.amazonaws.com URL it shows me an error message like this:

"The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved."

Any ideas?

Avatar

This is a limit enforced by Amazon that does not exist in the EC2-Classic setup.

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Appendix_Limits.html

You will have to contact them to increase this restriction.

Avatar

I'm in the same boat. Adam or Matt could you please post if you found a solution? Thanks.

Avatar

I figured out the issue with coffeescript not woking properly. On a Rails 4 app you will run into problems where it appears there is some conflict with turbolinks. Just use jquery.turbolinks and you should be good. Find the solution here: http://stackoverflow.com/questions/17881384/jquery-gets-loaded-only-on-page-refresh-in-rails-4-application

Avatar

I got the script running by changing sublime to subl since the command is not available on my machine. I added a comment to the Gist. Thanks to Vojtěch Kusý.

Avatar

Does this work for you on Chromium on Ubuntu, too?

Avatar

So did you find what the problem was? Because i have the same problem right now.

Avatar

Great screencast! One issue I am running into however, is the submit buttons reappearing when returning back to the page after having left. Any ideas on a fix?

Avatar

Doesn't painting.image.recreate_versions! do the trick?

Avatar

Seems to be ignoring scopes. When I want to view a scoped result set and apply a Ransack filter, it views the unscoped results...

def my_queue
@search = Ticket.open.where(:analyst_id => current_user.id).search(params[:q])
@tickets = @search.result.paginate(:page => params[:page], :per_page => 25)
render 'shared/tickets.html.erb'
end

Avatar

Thanks for this excellent railscast, Ryan!

pg_search is great, but setting up indexes and triggers can be tricky. Here's how I set it up, works great (like, 40 ms to search on 200K documents)

https://github.com/Casecommons/pg_search/issues/15#issuecomment-21884006

Avatar

'YAY THAT WORKS' - loving it! :)

Avatar

This is a great screencast. As a newbie to RoR these are invaluable.

After adapting the code to my project, I couldn't get the '.add_fields' js function to work. Clicking the link to add a child record did nothing.
I checked the web browser console and found this error when the page loaded: "TypeError: 'undefined' is not an object (evaluating '$(this).data('fields').replace')"

After struggling with it for a while I realized my indents were not set properly in the jQuery script. I feel like I need a beer...

Avatar

ActiveModel::MassAssignmentSecurity::Error in ShopsController#create

Can't mass-assign protected attributes: photo

app/controllers/shops_controller.rb:43:in `new'

app/controllers/shops_controller.rb:43:in `create'

getting an error please help me any one

Avatar

I came across this today when looking to test ActiveResource and it proved to work really nicely, however I then came across ActiveResource::HttpMock which is a specific mocking implementation for active resource which was even easier to get up and running.

Thanks for the cast though, set me on the right path of mocking the web request rather than the ActiveResource itself.

Avatar

I was installing from source and had to do this to get it to work

cd ruby-1.9(source directory used to install ruby)/ext/openssl
sudo ruby extconf.rb
sudo make
sudo make install
Avatar

Sorry for some reason the text regarding error didn't show up.
a.tags give the following error
#<ActiveRecord::Associations::CollectionProxy []>

Avatar

very cool thanks for posting the fix. I was lost. lol

Avatar

Hi Rails Newbie here. I am using Rails 4 and trying to implement tagging as instructed in this rails cast.
When I try to view the tags in the rails console with a.tags I get
#

Any help would be greatly appreciated.

Avatar

Sorry, maybe I'm not seeing it but what is stopping someone from simply setting a session called user_id manually in their browser. Wouldn't that allow them to steal someones account?

Avatar

Change:

elsif @user.update_attributes(params[:user])

to:

elsif @user.update_attributes(params.permit![:user])

Avatar

Yea, you just specify the dictionary in your tsvector and tsquery calls. tsquery('english','my search terms') or tsquery('simple','search this stuff'). Same with tsvector('simple',field).

Avatar

Hi,

What I did was

invoice.attributes = row.to_hash.slice(*Invoice.attribute_names())

Avatar

Im getting this error also. Im using simple_form...which doesnt seem to change anything. But, using Ryans code...getting the same validation error you were. What did you end up changing to get the validation to pass?

Avatar

I am interested in using this in a multi-tenant app. There is a hint at the fnordmetric.io site "Namespaces can be used to separate users if you are deploying FnordMetric as a white-label solution to your customers." I'd like to know how to do this dynamically in a running app so when a user creates an account an instance of fnordmetric is also setup and configured for him/her. I would appreciate any pointers on this.

Avatar

How update collection every 5 second.
this example, does not work in rails.

setInterval(function() {
channel.fetch();
}, 5000);

help me, please.

Avatar

Thanks for that. I think this will fix an issue I'm having with IE10 playing audio on jPlayer from S3. One question though - where in the fields order do you put the content type field? I know order matters and I've tried every combination to no avail. Any thoughts?

Avatar

Had a problem with local testing of my newly-built Gem. Bundler couldn't find the Gem at all when specified using :path => ~/src/rails/my_gem/pkg. When I pushed to Github and changed the Gemfile line to use :git =>, running bundle pulled the built Gem down from Github but then had a message that said

Could not find gem '(redacted) (>= 0) ruby' in git://github.com/jdickey/(redacted).git (at master).
Source does not contain any versions of '(redacted) (>= 0) ruby'

It would only work when I pushed the Gem to rubygems.org. This strongly implies to me that I should have added a source line to my Gemfile, but the episode didn't seem to cover that. Should it have?

Avatar

Anyone having trouble when using better_errors with Puma, where when an exception is thrown or error occur we don't get any information back from server response?

Avatar

I was facing the same problem. I found out the problem was because the latest "ember-rails" gem added a custom adapter for you, you need to set the "plurals" for that adaptor, but screencast set the config for the default one.

The simple solution is to delete the line adapter: DS.RESTAdapter.create() and force app to use default adaptor, and it should work

Avatar

Thank you very much, nice railscasts, helps a lot to learn and understand.

I would like if someone do some test with capybara, if her/him could post it, it would be really helpful :)

THANKS RYAN!!!

Avatar

As per the comments above I tried doing that and
@collection.fetch({reset:true})

But for some reason I keep getting this error
Uncaught TypeError: Object triggered has no method 'call'

Also I am using rails 4.

Let me know if I am missing something.

Avatar

I just tried running this code on my windows machine. While I can get the file upload to work on Firefox, IE and Safari browsers. It simply doesn't work in Chrome browser. When I select a file, neither the filename shows in the paintings page nor the file gets uploaded to the server. Anyone else faced a similar problem?

Avatar

Does anybody know how to use this with delayed_jobs and delayed_paperclip. I am getting a "ActionView::Template::Error (Paperclip::Errors::NotIdentifiedByImageMagickError)". It points to:

ruby
  def avatar_geometry(style = :original)
    @geometry ||= {}
    avatar_path = (avatar.options[:storage] == :s3) ?   avatar.url(style) : avatar.path(style)
    @geometry[style] ||= Paperclip::Geometry.from_file(avatar_path)
  end

I'm really surprised there isn't much documentation of delayed jobs with paperclip. Sure cropping is great but what is the point if it takes 10-15 seconds to process an image. Please help me!

Avatar

Thanks for the railscast, can't tell you how many times this it's helped me on projects. I was trying this out but I seem to have a problem when the user clicks on the password reset link from their email I get an error saying that it cant find the user with the password reset token

`ActiveRecord::RecordNotFound in PasswordResetsController#edit

Couldn't find User with password_reset_token = eydSfVtGn2gBQyNJP0o9jA`

Avatar

I just figured it out!

For the search form you need to use on()

ruby
$(document).on('submit', '#identities_search', function () {

$.get(this.action, $(this).serialize(), null, 'script');

return false;

It is really annoying because it doesn't throw any kind of error, the only reason I got it working is from having to get the sort working out before. Hope this helps someone.

Avatar

I am having this same issue. For some reason my submission only goes through the AJAX path for the first submit, after that it refreshes the page through the url. I would also really appreciate any thoughts on this

Avatar

Hello!

My application is working proper on local host.But I am getting error on heroku.I am getting following error when I tried to post message through console.

curl http://ramfayeserver.herokuapp.com/faye -d 'message={"channel":"/messages/new", "data":"hello", "ext":"secret"}'

[{"channel":"/messages/new","error":"Incorrect token.","successful":false}]cis@CISM189:~/Desktop/atradeship-chat$

I have following setting in my private_pub.yml
server: "http://ramfayeserver.herokuapp.com/faye"
secret_token: "batkaro"

I referred this from follwing url:
http://webprogramming29.wordpress.com/2013/02/15/how-to-use-private_pub-gem-on-heroku-in-ruby-on-rails/

Please help me for that
Thanks

Avatar

Great advise Eric! you save me a lot of time.

Avatar

Hi there,

I'm having an issue. So far I installed it and run the migrations :

Ruby
gem 'acts-as-taggable-on', '2.4.1'
Terminal
rails g acts_as_taggable_on:migration
rake db:migrate

But then as soon as I add this line :

Ruby
acts_as_taggable

into my model, I've got the following error :
wrong number of arguments (3 for 1..2)

I'm using Ruby 2.0.0-p247 and Rails4.0.0.beta1 (The project is already pretty big and we can't dare to update the Rails version).

Anyone already faced the same issue?

Thanks a lot

Avatar

It looks like shortly after this podcast was made, they added deploy:cleanup by default:

https://github.com/capistrano/capistrano/wiki/Capistrano-Tasks#deploycleanup

So need to call it explicitly anymore.