RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Exactly! Thanks for the tip. Just restarting the server made it work.

Avatar

Ryan,

Are you planning on doing an update for Rails 4 compatibility?

cheers.

d

Avatar

When a memcached server runs low on memory, it simply removes the oldest data.

Avatar

Well, yes, the point of caching is to trade memory for performance.

memcached is very scalable - for example, one popular social networking service reported in 2008 that they operated over 800 memcached servers, delivering 28TB of available cache memory.

Avatar

I can't get it to work when i add this into my app.

undefined method `import' for

i have gone at it over and over -- and nothing.

-- though I can get it to work using the supplied source code.

please assist -- i have lots of content entered in good cspreadhseets taht I need to enter into my site.

thx,

sg

Avatar

My import button is not showing up in any browsers. I used this snippet in my customer.rb

ruby
def self.import(file)
 CSV.foreach(file.path, headers: true) do |row|
  Customer.create! row.to_hash  
 end
end

and this in my index.html.erb

ruby
<%= form_tag import_customers_path, multipart: true do %>
  <%= file_field_tag :file %>
  <% submit_tag "Import" %>
<% end %>

Any thoughts?

Avatar

Great gem.

Params seem very helpful. From the controller, is it possible to filter public activity by params (for example, storing the recipe in the params and only showing public activity for a recipe on that recipe's page)?

I see in the episode that Ryan filtered directly by one of the attributes (owner_id):

ruby
def index
  @activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.friend_ids, owner_type: "User")
end

I see that I can store the recipe_id from within the recipe controller similar to what was mentioned in the episode:

ruby
@recipe.create_activity :create, owner: current_user, :params => {:recipe_id => @recipe.id}

I see that it's possible to filter this way in the view (replacing "123" below with the particular recipe's id, but I'm assuming it's better to do this in the controller, yes?

ruby
<% if activity.trackable && activity.parameters[:recipe_id] == 123 %>
        <%= activity.inspect %><br>
<% end %>
Avatar

Thank you thank you thank you! I've been stuck on this for hours!

Avatar

my mistake the log says "Unpermitted parameters: utf8, authenticity_token, venue, commit" but I had an error in my code which compounded things

Avatar

You're saying multiple times that the cached values are expired, that's a bit false I think.
The cache key changes and there is no cached value with the new key, but the cached value with the old key is still cached in there. It can grow big if not expired from time to time.

Avatar

I am trying to use Strong_parameters with Ajax & I get the following

Unpermitted parameters: utf8, if I do not include it in the permitted or

ActiveRecord::UnknownAttributeError (unknown attribute: authenticity_token): if I do

Is this me or a Work in progress I can make it work for a html form.

ruby
puts "<%= simple_form_for(@venue, remote: true ) do |f| %>"
Avatar

Try bbarton's suggestion - it worked for us.

from bbarton
modify...

where("to_tsvector('english', title) @@ :q", q: query)

... to..

where("to_tsvector('english', title) @@ plainto_tsquery(:q)", q: query)`

Also a couple of gotcha's was default scope and multiple includes.

We had to run the text_search as 'unscoped.where' and remove a couple of includes before any search results would displayed.

This app had one search query only on strings such as names, usernames, and email addresses (no full text searches). so we incorporated Ryan's Auto Completion:

http://railscasts.com/episodes/102-auto-complete-association-revised

It works great. Thank's Ryan!

Avatar

Hi

Can anyone tell how to export 100,000 records of data to csv in seconds.

Thanks in advance.

Avatar

Thanks, I couldn't get the handler to open sublime, this should work for now

Avatar

Thank you so much Daniele. Is this issue with new jquery version only.

Thanks,
Shyam
http://about.me/shyam_visamsetty

Avatar

I don't think this is a good idea. What if a user changes a password because it was compromised? - You would need to change the member ID to log them out which is a really bad idea.

Avatar

Hi, I got this question. What if in the bar action, instead of saying

ruby
def bar
  count = @@count
  count += 1
  @@count = count
  render text: "#{@@count}"
end

The developer can just type as:

ruby
def bar
  @@count += 1
  render text: "#{@@count}"
end

Is my last code considered to be thread-safe?

In Java, we may need to put a keyword 'volatile' on variables of an object which is shared across different threads. What about Ruby in our case ??

Thanks if you could let me know

Avatar

What about controller testing? - I have a bunch of integration tests with capybara which are great, but not sure how to write the controller tests.

Avatar

Indeed! Thanks for posting about the update.

Avatar

Help please,
followed the tutorial but when I use cap rubber:create_staging I get the following error:

Creating instance ami-b6089bdf/c1.medium/likeme_production_default,likeme_production_web,likeme_production_web_tools,likeme_pr
oduction_production,likeme_production_apache,likeme_production_app,likeme_production_passenger,likeme_production_collectd,likeme_p
roduction_common,likeme_production_monit,likeme_production_db,likeme_production_postgresql,likeme_production_postgresql_master,lik
eme_production_elasticsearch,likeme_production_examples,likeme_production_graphite_server,likeme_production_graphite_web,likeme_pr
oduction_graylog_elasticsearch,likeme_production_graylog_mongodb,likeme_production_mongodb,likeme_production_graylog_server,likeme
_production_graylog_web,likeme_production_haproxy/us-east-1
/home/alon/.rvm/gems/ruby-1.9.3-p429/gems/excon-0.22.1/lib/excon/middlewares/expects.rb:10:in `response_call': Expected(200) <=> A
ctual(400 Bad Request) (Excon::Errors::BadRequest)

Avatar

How do I do the same for a authorized user, I've got the following in my controller, model, and index;

Controller:
def index
                @bins = Bins.new
                @bins = Bins.all
                @tw = Newtweets.order("tweet_id desc").limit(100)
        end
def pull
     current_user.newtweets.pull_tweets
     return
end
Model:
def self.pull_tweets
          twitter.home_timeline(since_id: maximum(:tweet_id)).each do |tweet|
                  unless exists?(tweet_id: tweet.id)
                          create!(
                                  tweet_id: tweet.id,
                                  followers: tweet.user.followers_count,
                                  retweets: tweet.retweet_count,
                                  time_date: tweet.created_at,
                                  content: tweet.text,
                                  screen_name: tweet.user.screen_name,
                          )
                  end
          end
  end
Index:
<% @tw.each do |t| %>
                <div class="entry">
                    <div class="selection"><%= check_box_tag :label %></div>
                    <div class="stamp unknown"><%= t.time_date %><br /><span class="date"><%= date.day %>/<%= date.mon %>/<%= date.year %></span></div>
                    <div class="tweet">
                            <p><%= t.content %>
                        <br /><span class="username"><a href="https://www.twitter.com/<%= t.screen_name %>" target="_blank">@<%= t.screen_name %></a></span><span class="followers">Followers:<%= t.followers %></span><span class="retweets">Retweets: <%= t.retweets %></span></p>
                    </div>
                </div>
                <hr style="width:93%;height:1px;margin:-5px auto 10px auto;border:none;border-bottom:1px solid #EDEDED;" />
                <% end %>

As you've guessed it, I'm trying to use a refresh button to pull the route /refresh which runs the controller, that runs the model??

Not sure I'm doing this right. However, going in the console with the following command;

ruby
u.newtweets.pull_tweets

I get an error: NameError: uninitialized constant User::Newtweet

Should I be moving the self.pull_tweets stuff into a controller??

Any suggestions, thank you!

Avatar

Is there an easy way to populate my database with the test data shown in the screencast?

Thanks in advance!

Avatar

What a name I thought this screen cast was going to be about Borland JBuilder(late 90's editor) ;)

Avatar

I`m clone repo
git@github.com:railscasts/381-jquery-file-upload.git

bundle
rake db:migrate
rails s

but js and css file does`t load.

If I look at the source code of a site:

link href="/assets/application-7270767b2a9e9fff880aa5de378ca791.css" media="screen" rel="stylesheet" type="text/css" /

script src="/assets/application-673db32530fb40e931676ebc22eaebc6.js" type="text/javascript"/script

Why don`t load other js/css file?

Avatar

Put this at the top of your model which inherits from ActiveResource

ruby
@headers  = { 'Authorization' => "Token token=\"#{ENV['API_KEY']}\"" }
Avatar

This worked for me as well. Thanks!

Avatar

After upgrading to the latest jquery and adding Facebook 'Like' buttons, the sign-in popup window stopped functioning.

Firebug reported:

FB.getLoginStatus() called before calling FB.init().

To fix this, just move the "FB.init" call to the last position in facebook.js.coffee.erb.

app/assets/javascripts/facebook.js.coffee.erb
jQuery ->
  $('body').prepend('<div id="fb-root"></div>')

  $.ajax
    url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
    dataType: 'script'
    cache: true


window.fbAsyncInit = ->

  $('#sign_in').click (e) ->
    e.preventDefault()
    FB.login (response) ->
      window.location = '/auth/facebook/callback' if response.authResponse

  $('#sign_out').click (e) ->
    FB.getLoginStatus (response) ->
      FB.logout() if response.authResponse
    true

  FB.init(appId: '<%= ENV["FACEBOOK_APP_ID"] %>', cookie: true)

Worked for me - not sure why.

Avatar

rake assets:clean and rake:assets:precompile to override the bootstrap_and_overrrides.css.less

Avatar

You're a lifesaver! Spent too long figuring this out, and was starting to suspect it was a versioning issue.

Avatar

I developed a wizard using Angular JS. It is extremely simple and requires less code. It allows users to go back and change previous values. It's on github: https://github.com/bparanj/angular-wizard

Avatar

Hi Guys,
Not sure how scalable model caching is?
In a sense, it looks like we are building a "cached mini DB"..
in a scenario with thousands (or millions) of records , you will end up requiring more and more memory.

Avatar

Thanks for the reply and sorry for the slow response. That was great link.

Avatar

Nice. Any idea on how to deploy with Capistrano? I didn't find recipes.
Many thanks in advance.

Avatar

For all the guys with this problem:
"Validation failed: Password can't be blank, Password is too short minimum is 6
characters"

the solution is just change the line

ruby
  save!

and use instead

ruby
save!(validate: false)
Avatar

Ryan, there is one hidden bug in this episode.

Is:

ruby
Redcarpet::Markdown.new(renderer, options).render(template.source).inspect

Should be:

ruby
Redcarpet::Markdown.new(renderer, options).render(template.source).inspect.html_safe

You won't see any difference unless you try writing partials in Markdown. I'm on Rails 3.2.12.

Avatar

A BIG Thank You Egbert! - Worked for me!

Avatar

Maybe this can help those like Michael Elfassy, SMnetserv, pbaileyjr12 who have difficulty with double named countries.

On my app, everything worked fine until I accidentally 'bundle update' the gems.

After the bundle update, the double name countries (United States and United Kingdom) would not trigger and display the:

grouped_collection_select :state_id, Country.approved.includes(:states)

sidenote: bullet says to include states in the query.

I hope this helps:

app/assets/javascripts/people.js.coffee
original
escaped_country = country.replace(/([ #;&,.+*~\':"!^$[\][()=>|\/@])/g, '\\$1')

modified
escaped_country = country.replace(/([ #;&,.+*~\':"!^$[\][ ][()=>|\/@])/g, '\\$1')
Avatar

Thanks! Was having trouble setting this up, great episode and much appreciated : )

Avatar

Thanks for reporting this error in the ASCIIcast, I have corrected it.

Avatar

In an act of shameless self promotion, I'd like you to promote http://pulsar.nebulab.it

You can use it to organize capistrano recipes and configurations. Maybe you'll find it useful.

Avatar

Hey it will be great to make a new video for thinking sphinx, a lot of things changed so your video is no longer relevant.

Avatar

If you're getting an endless loop of updating, change to:

  def reprocess_photo
    photo.assign(photo)
    photo.save
  end
Avatar

The helper_method part does not work using Rails API's controller:

class ApplicationController < ActionController::API

This is because ActionController::API#helper_method is simply a stub that does nothing.

I just needed to include AbstractController::Helpers in my ApplicationController to make it work.

 include AbstractController::Helpers
Avatar

Thank you, I had run into the same issue. This fixed it.