RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

my mistake was that I did not add 'survey_id:integer' while generating questions model. it solved the problem

Avatar

Can you expand on when you should and shouldn't use polymorphic associations? I was thinking of using them for :imagable photos on my applications (users, events, classes, projects, etc all have many photos each via Paperclip). Seems like a great way to make some very DRY code.

Avatar

I'd love to see this. My Textmate-fu is weak compared to Ryan's and I'm constantly picking up little tips from him. I'd love to see more in the same place.

Avatar

Hi guys, i've ran into this problem.

ActionView::MissingTemplate in Notes#index

Which fails at: <%= render 'notes' %>

Should i be adding anythign else to my controller?

def index

@notes = Note.search(params[:search])

end

Avatar

Quick and dirty:

  1. Open .bash_profile in your favorite editor eg:
    mate ~/.bash_profile

  2. Add the two ENV variables like so:
    export TWITTER_KEY=your_twitter_key
    export TWITTER_SECRET=your_twitter_secret

  3. Save and close the file

  4. Either quit your terminal session & restart or reload it with:
    source ~/.bash_profile

Avatar

Great screencast, but I got stuck. Don't know how to set them ENV['TWITTER_KEY'] and ENV['TWITTER_SECRET'] variables. How do I set them? Is there a config file for that?

Would really be glad If anyone could help.

Avatar

did you have to restart nginx or the app?

Avatar

Try rack api throttling with a rack middleware. I forked it to limit throttling to a certain path: https://github.com/christoph-buente/api-throttling

Avatar

nevermind im about to throw my pc out the window
had to use dos2unix on the unicorn_init.sh in order to get it to insterpret it righ

thanks!

Avatar

for some reason, at the last step on cap deploy:cold it is not allowing me access. this is the output:

console
  * executing `deploy:start'
  * executing "/etc/init.d/unicorn_mock_app start"
    servers: ["MYIP"]
    [MYIP] executing command
 ** [out :: MYIP] sh: /etc/init.d/unicorn_mock_app: Permission denied
    command finished in 150ms
failed: "sh -c '/etc/init.d/unicorn_mock_app start'" on IP

I tried changing the permission to the symlink by running:

console
chmod +x /etc/init.d/unicorn_mock_app

But then it outputs

console
-bash: /etc/init.d/unicorn_mock_app: /bin/sh^M: bad interpreter: No such file or directory

any ideas?? on why it wont allow permissions for the app to start

Avatar

Just had to give a thumbs up to the first ever episode

Avatar

I have started playing with meteor. Developing is very smooth and fun. I get this "it just works" feeling, although there is still a lot missing in meteor. ;-) Actually I started first with derby as well, as it was also more appealing to me, however, I couldn't even get the examples to work. And reading the issues I found I'm not the only one.

Avatar

in ASCII-Cast, the view of the form should be

ruby
<%= form_for @survey do |f| %>
  <%= f.label :name %><br />
  <%= f.text_field :name %>

  <%= f.fields_for :questions do |builder| %>
    <%= builder.label :content, "Question" %><br />
    <%= builder.text_area :content, :rows => 3 %>
  <% end %>

  <p><%= f.submit "Submit" %></p>
<% end %>

you forgot the = (equal sign), so the questions would not appear ;-)

keep on casting, very good work ryan
marcello - railszilla.com

Avatar

You can't use "upstream unicorn", you have to customize for each app "upstream unicorn_app1". I got stuck there too.

Avatar

I've toyed with Derby and Meteor quite a bit over the last few weeks. Derby JS is by far my favorite. The biggest hurdle for both of these frameworks as a node novice has been lack of documentation but both of these frameworks are nothing short of revolutionary! Meteor has several full time programmers and a larger following, but at the end of the day Derby just makes more sense to me.

Avatar

pg is transactional and just generally pretty nice.

Avatar

What happens if the access token expires? The user should be not allowed to login again and should go through the Oauth process again, and the database should be cleaned for this user.

Avatar

Great episode! looking forward to see next episodes on recurring billing.

Avatar

What's the most elegant way to use draper in common with the ancestry gem from episode #262? How do I get all children and parents easily decorated?

Avatar

Got this up and running but seems to indent any code after line 1 by an extra four spaces. Anyone know if this is a pygments or Redcarpet issue or how to fix it?

Avatar

I'm in the same boat, I'd love a little guidance on this.

Avatar

Hi Everyone,
I'm trying to work with https, I used this configuration (https://github.com/ryanb/private_pub#serving-faye-over-https-with-thin)
and I declared the gem directly from github gem "private_pub", :git => "https://github.com/ryanb/private_pub.git".

I'm pretty sure that the certificates place correctly and I'm still getting this error while I'm trying to publish something:
Exception
OpenSSL::SSL::SSLError
Error
SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

Thanks a lot

Avatar

UPDATE: You have to wrap the following code around the columns loop to get it working with migrations:

ruby
if self.table_exists?
  ...
end
Avatar

I can access the '/api/resource.json' but there is an error while trying access '/api/v2/resource.json'

No route matches [GET] "/api/v1/companies/00000000000001/reports.json"

No route matches [GET] "/api/v2/companies/00000000000001/reports.json"

Avatar

Great, thanks. I'll look into it straight away :-).

Avatar

thanks! ENV["DATABASE_URL"] = "postgres://localhost/mailer_development" doesn't work for me as well.

but i get "undefined method `load_functions' for QC::Queries:Module" when trying to migrate, why is this?

Avatar

Chapter 8 of railstutorial shows you how to do that: http://ruby.railstutorial.org/chapters/sign-in-sign-out#top

Pay particular attention to section: 8.2.1 titled "Remember me"

Avatar

I would love to see the match operator make its way into ActiveSupport. Such an awesome, clean syntax.

Avatar

Sure, everyone, who has

FATAL:  could not create shared memory segment: Cannot allocate memory
DETAIL:  Failed system call was shmget(key=1, size=1646592, 03600).

problem, can easily fix this.
Run:

sh
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216

(The first one's the critical one, but second seems appropriate too.)
This changes the limits in the currently-running kernel. To make these values stick across reboots, add them to /etc/sysctl.conf, like this:

kern.sysv.shmall=65536
kern.sysv.shmmax=16777216

Found this here

Avatar

Ryan says in the end of the cast that Meteor is "only" for rich client side applications he is not normally working on. It appears to me though the trend for ALL web apps is currently exactly going towards that direction. Towards more interactive, javascript rich and snappy websites. As it is stated on the DerbyJS website: why not having realtime data push updates as a default on all websites if it is possible? To me it seems frameworks like Meteor and Derby are the future of web development. They also significantly improve the development experience by making browser reloads unnecessary. Opinions? I'd love to hear what others think. Especially, are there any use cases where "traditional" server side heavy frameworks like Rails are fundamentally working better than those new type of frameworks?

Avatar

I do not want the event to occur every day, I want the event to occur only on Monday / Wednesday / Friday or Tuesday / Thursday between two different dates.

Please, somebody help me, I need a lot.

Since now I thank

Avatar

Very useful screencast Ryan.

I'm using a generate_access_token in my User model to create an access_token for each user so that my app can do "Remember Me" using a cookie (so they don't need to login again) as per screencast #274.

Would I use this same access_token field for the user to be able to call my API?
Can you see any issue in doing that?
Or should they be different?

Avatar

Since prepend_view_path seems to be depreciated in rails 3.2, im looking for the "right" way todo it in 3.2.. any thoughts anyone?

Avatar

Goog question from Brandon Williams. Can Jbuilder templates be used inside of layouts?

Maximum that I have been to achieve is this:

ruby
# v1.json.jbuilder - layout
json.request do |json|
  json.url "https://api.storyful.com/stories.json"
  json.status 200
end
json.data JSON.parse(yield)

# show.json.jbuilder - action view
json.test 'test form show'
Avatar

pjax_rails gem has changed significantly since this railscast was released and hence if you are trying to use it as per screencast, you may face errors.

First thing is, pjax_rails plugin does not add that pjax handler by default to all the links anymore. You will have to specify the elements for which you want pjax to work via, $('a').pjax('#data-pjax-container')

Seond thing, pjax_rails will automatically disable layout rendering if it it detects request is of type pjax.

Avatar

From looking at the source quickly -- it seems only the User model is slightly different as some logic from the controller was moved to it.

What's new in this episode?

Avatar

Taps stopped working with Rails 3.2.5 for some reason, so I thought I'd finally give Valkyrie a try.

Whoa! Nice. Easier than I expected, although it's significantly slower pushing local data to my remote postgre db server on Linode.

Avatar

I needed a:

ENV["QC_DATABASE_URL"] = "postgres://localhost/mailer_development" if Rails.env.development?

instead of:

ENV["DATABASE_URL"] = "postgres://localhost/mailer_development"

in config/initializers/queue_classic.rb

The two differences:

1) Only set the url in development so when I deploy to Heroku the production database url gets picked up.

2) Use QC_DATABASE_URL instead of DATABASE_URL. Apparently Rails actually uses DATABASE_URL instead of database.yml if DATABASE_URL is present. This will cause your tests to start failing, despite the Rails.env.development? guard, due to the initializer running prior to Rails.env getting set to "test". This is confusing, but put a puts Rails.env into the initializer and watch the output when you run rake test and you'll see "development" and then "test" as Rails runs your tests.

Hope that helps someone. Great Railscast as always Ryan!

Avatar

Awesome railscast Ryan! One thing... each time I log into my application (www.Meer.li), it logs me out whenever I close the browser. How do I save and retrieve the user with a cookie instead of the session, so the user will be logged in automatically when he visits the page the next time?

Hope you have a solution. Would really appreciate it!

Avatar

Changed from Bj(no longer supported in Rail3) to Delayed_job but seems not to handle rails runner.

lib/report_job.rb
class ReportJob < Struct.new(:prawn_script_name , :account_id )
def perform
bundle exec rails runner "#{Rails.root}/jobs/#{prawn_script_name}.rb #{account_id}"
end

Error in last_error field.
{undefined method `runner' for #ReportJob:0xc28f080

OUCH! .... will try Resque.

Avatar

Between this and Private Pub seems like a great solution. I have a use case for this gem however I will be using devise for authentication and need to somehow get the current_user and have them show up in a chat window.

Does anyone know a clean way to get this or something similar working. It's kind of pointless to have a chat system with 20 people logged in whom you can't tell who's who.

Thanks!

Avatar

@search = Product.solr_search do