RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi
any idea why the content in field with the .tokenInput() is not sent with the rest of the form? I'm using mongoid

in my coffee script file:
$("#profile_tagg_tokens").tokenInput '/taggs.json'
theme: 'facebook'
In my form (using slim)
=f.text_field :tagg_tokens

In my model

attr_accessible :user_tags, :displayname, :city, :country, :tagg_tokens

attr_reader :tagg_tokens

What I'm trying to achieve is:
- user creates his profile(city, displayname, etc...) and selects taggs from a taggs list

My issue is as soon as I call .tokenInput on the taggs_token text_field, the content is not sent when the form is submitted
Thx for your help

Avatar

Yep, but what if track_activity fails? That's what Steve means I believe.

Avatar

Might be a basic Rails question but:

In
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.friend_ids, owner_type: "User")
where did current_user.friend_ids come from?

friend_id is an attribute of Friendship, not User, right? And you can just pluralize an attribute to get an array?

Avatar

Have you thought about doing this with redis as demonstrated by obie here? - http://www.youtube.com/watch?v=dH6VYRMRQFw

Avatar

I'm finding Capistrano a little daunting, and am trying to set up NGINX and Unicorn on my VPS.

Unicorn_rails works like a charm right now when called from the app_root, but then I'm stuck with my terminal open.

Can't get the unicorn command to work, let alone start it up on VPS reboot. I get:

/usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/lib/unicorn/configurator.rb:634:in `parse_rackup_file': rackup file (config.ru) not readable (ArgumentError)
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/lib/unicorn/configurator.rb:77:in `reload'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/lib/unicorn/configurator.rb:68:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/lib/unicorn/http_server.rb:108:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/lib/unicorn/http_server.rb:108:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/bin/unicorn:126:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p385/gems/unicorn-4.6.0/bin/unicorn:126:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/unicorn:19:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/unicorn:19:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'

Also, I keep hearing that unicorn is supposed to create a /tmp/unicorn.pid file, but I can only ever find /tmp/server.pid is that the right one?

Can Anyone help on that?

Avatar

Are you sure you have the rails gem installed? Or ruby?
If it can't find the rails command then one of those is probably missing I would think.

I think you'd want to try rbenv or rvm to install some rubies, and then do:

gem install rails
Avatar

I don't really care if it is a lot less code. Using Backbone creates much more readable and extensible code that is a requires a lot less clutter in the markup.

Angular seems like a great tool, but feel like I would have a hell of a time coming back months after I wrote it trying to tease apart the js and the markup, let alone doing the same if someone else wrote it. I like to keep my markup super clean.

Avatar

Great episode. On quick question though. I would've thought that the presenter in this case would be 'just' a helper. Why did you make it a presenter? Thanks!

Avatar

@Nguyen Duc Giang.

add a billing address to your purchase.

response = gateway.purchase(1000, credit_card, :ip => "127.0.0.1", :billing_address => {
:name => "Test Guy",
:address1 => "123 W 423 E",
:city => "Somewhere",
:state => "CA",
:country => "US",
:zip => "88888"
}

Avatar

Pretty new to Refinery world. Any clue on how to turn on multilanguage engines support to Refinery? Locales yml files are correctly generated. Thanks.

Avatar

Adding a trim() should do the trick

tmpl("template-upload", data.files[0]).trim()
Avatar

I did a slight variation of this project, and I was able to create new records (that persisted), the only problem is that now I pushed the app to heroku, records no longer persist.

It was working fine locally, so either it has something to do with precompiled assets, or there's some strange discrepancy when switching from sqlite to postgres.

Link to Repo:
https://github.com/lukethomas14/Angular-Todo

Link to App Deployed on Heroku:
http://angularfun.herokuapp.com/

Avatar

Currently handlebars_assets supports haml (as well as slim). See readme for details.

Avatar

Outstanding overview of SASS. And thanks for the color wheel popup tip in TextMate; I didn't even know about that!

Avatar

The track_activity method is only called if the @recipe.save succeeds in the episode.

Avatar

Great Railscast, though I felt Rails Composer was sorely missing; seems like it's becoming the de-facto solution for this kind of thing.

Avatar

I've been using Streama with Mongoid, which has a nice DSL for logging activity stream and specify cached attributes. https://github.com/christospappas/streama The only thing missing is auto expire old activities.

Avatar

"In Angular, the DOM is your view."

I think this is the same mistake that Rails did since its beginning: mixing up the concepts. Instead, the DOM is a template, the view is an object which is responsible for the presentation of a model (see BackboneJS or Mustache).

Avatar

I really love this gem, It works just perfect for my current project(still in development) except sooner or later I am going to have to replace it with alternative or write from scratch as I hit the performance issue:(

Avatar

I don't see why you keep saying that you cannot get the user reference in the model. On create the activity owner would be the creator referenced in the recipe/comment. If other users can update these, you would likely store the last modifier in the database for later reference anyway, so you can also reference them in the callback.

For me, this functionality does belong in a callback and nowhere else, precisely because it is possible that there are other ways, these items can be created. Things like combining/filtering/spam protection would also have to be implemented when you create activities in the controller at some point of professionalization of an app. So this is no argument against callbacks.

Avatar

From the documentation it is possible to include draper as a module:

https://github.com/drapergem/draper#making-models-decoratable

Avatar

I as an admin have 1200 friends. Delaying the activity creation is the only real option even if it only takes a few seconds.

Avatar

Why not just mark the model as 'deleted' instead of actually destroying it?

Avatar

Does Capistrano not create an error log?

Avatar

I also get the bundle install error:


failed: "sh -c 'cd /home/deployer/apps/burden_farming/releases/20120322200251 && bundle install --gemfile

But it does not tell much, how to debug? How can I find out which gem dependency is causing the error?

Avatar

I just want to point out that using eval to execute anything that comes over the channel is really insecure and opens you up to XSS attacks.

Also, Ryan forgot to delete the FAYE_TOKEN from outgoing messages in his Faye extension, so anyone who connects to his chat app could execute arbitrary code on all of the connected clients...

Avatar

Ahhh.. just found why the border-radius error is still there... it is because this include has been removed from bourbon. http://bourbon.io/docs/#border-radius

Make a minor change in projects.css.scss to replace the border-radius line with the following four lines:

@include border-top-radius(6px);
@include border-bottom-radius(6px);
@include border-left-radius(6px);
@include border-right-radius(6px);

Avatar

That's one option, the other is to pass the arguments as strings in the array as shown in Nick's example. His example will minify properly.

Avatar

This does not work in my system: Ubuntu 10.04, Rails 3.2.11

But this worked:

rails new store
spree install store -A
cd store
rails s

Next the address http://localhost:3000
will give u the spree web page.
login with spree@example.com
password : spree123

u will get the admin screen.

Refer the website:
http://checkedexception.blogspot.ie/2012/05/installing-spree-from-scratch-on-ubuntu.html

Avatar

I'm getting this error when running cap monit:setup

/ruby-1.9.3-p327/gems/capistrano-2.14.1/lib/capistrano/configuration/variables.rb:122:in method_missing_with_variables': undefined method
template' for #Capistrano::Configuration:0x8ce5a24 (NoMethodError)

Avatar

By using a service object you could wrap the save of recipe (e.g.) and the creation of feed in a transaction. Otherwise you could have an activity succeed without its companion feed row being created.

Avatar

I'm using this technique to add/edit multiple people to/in a household. It's a rails 4 application using turbo links along with query.turbolinks.

My application also uses jQuery datepicker plugin.

My _person_fields partial includes a date field that uses the date picker plugin, but it doesn't work. The datepicker is not being initialized in the dynamically added person_fields partials.

I've tried several methods from the Turbolinks episode with no success.

This is beyond my familiarity, but I think I need to somehow call document ready after the person_fields partial is added. Don't know how to do that.

Any suggestions are appreciated. Thanks!

Avatar

Thanks Ryan for a great (as usual) screencast, and Piotrek for a nice looking gem.

My main problem with the polymorphic approach is that we loose information when models get destroyed. For instance, using the example in the screencast, I'd like to display the name of a recipe that got deleted.

This obviously means that the activity has to duplicate all the data it wants be able to display after model destruction.

Do you know of any work-around or non-polymorphic gem that does that?

Avatar

Thanks Ryan!
It was very useful, but a review is needed, Savon has changed a lot in version 2, and it's very important working with delayed jobs...

Avatar

The official docs says to require all 3 gems (Linux, OS X and Windows). The gem will know which one to use.

ruby
group :development do
  gem 'rb-inotify', :require => false
  gem 'rb-fsevent', :require => false
  gem 'rb-fchange', :require => false
end
Avatar

Would you like to discuss this further on Github Issues? This is really interesting, but querying for Activities with Redis requires a whole different process.

Avatar

Note that link_to signout should contain :method=>delete
as shown below:

/app/views/layouts/application.html.erb

<% if user_signed_in? %>
Signed in as <%= current_user.email %>. Not you?

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

<% else %>
<%= link_to "Sign up", new_user_registration_path %> or
<%= link_to "Sign in", new_user_session_path %>
<% end %>

Avatar

Ryan, it looks like in the second half of the episode you were really after ActiveRecord's to_partial_path, which you can define in Activity model and have it perform all of your path-building logic. It becomes a clear winner when you notice that

"activities/#{activity.trackable_type.underscore}/#{activity.action}"

becomes

"activities/#{trackable_type.underscore}/#{action}"

Makes more sense to have it come from inside the activity object itself. In the view you could then simply call render activity, and it would automatically call to_partial_path on the model. When this logic is moved into model like that, presenter is left somewhat empty, and in this specific case becomes excessive.

Avatar

hey can anyone please help me with the following problem:

  • executing "kill -s USR2 'cat /tmp/unicorn.sample.pid'" servers: ["server"] [server] executing command ** *** [err :: server] bash: line 0: kill: cat /tmp/unicorn.sample.pid: arguments must be process or job IDs command finished in 1023ms** failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.3' -c 'kill -s USR2 '\''cat /tmp/unicorn.sample.pid'\'''" on server
Avatar

I recently just finished a series that walks through building a scalable Backbone application layer by layer. It introduces a lot of patterns and concepts for building large Backbone applications alongside the Marionette framework. Marionette removes a ton of Backbone boilerplate and gives you application components you can leverage.

Whenever I watch or read other tutorials there is always a ton of misinformation, zombies being created, or ridiculous amounts of boilerplate code. So I've been working to show other Rails developers how to avoid these pitfalls and solve common problems.

Marionette is worth looking into regardless if you're developing with Backbone. It's site is here: MarionetteJS and you can find the series I've put together here: BackboneRails.com

Avatar

I've been using Marionette for 6+ months in a production app of around 700+ JS files. It goes together with Backbone like peanut butter jelly :-)

Marionette reduces a ton of the Backbone boilerplate stuff you see in virtually every tutorial / screencast. Marionette's docs are great but there's been a lack of real world use cases / screencasts about it - until recently. Check out MarionetteJS for several good links or BackboneRails.com since you're probably looking to see a scalable app built alongside Rails.

Hope this helps!

Avatar

Rails is a great anchor for working with any kind of JS MVC Framework. Through the use of the Asset Pipeline, JSON Generation gems like Rabl covered in this Railscasts and even gems like Gon also covered here along with the myriad of gems for use with JS templating (like ECO) you get the benefit of turning Rails into an amazingly streamlined API, built to support rich client side applications.

There isn't really an answer to the "correct" nor the "best" JS MVC Framework to use. I've personally built a large scale application (700+ JS files) using Backbone alongside Marionette. It's been awesome. There is a critical lack of sites dedicated to showing real world applications built leveraging these frameworks with Rails. Anyway I know this is an Angular episode, but I figured I'd point out BackboneRails.com because it can give you insight into the Backbone world of building apps with Rails, and can maybe help you make the decision that's best for your app. :-)

Avatar

If you edit the object multiple times, then multiple Activities are created each time.