RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Muchas gracias por este tutorial lo implementare en el proyecto que entregare el dia viernes :)

Many thanks for this tutorial i implement it in the proyect i have to give in my job many thanks

Avatar

I had that issue as well and you have to make sure aws_access_key_id , aws_secret_access_key, and bucket are not nil.

Avatar

Hey Leonel, thanks for not deleting your comment - it helped me after a couple of hours scratching my head. Seems the 'get' calls need to explicitly point to the controller#action when doing things this way. Thanks dude!

Avatar

This is most mind-expanding episode I've watched so far. I can't even get myself to code today because I keep thinking of ways to implement this into my project. It's possible I could remove dozens of files and lots of complexity, while improving the testability with this method.

There's nothing like having the author of cancan explain authorization. Thank!

Avatar

I needed to use chsh to change the default shell after installation:

console
chsh -s /bin/zsh

I also installed zsh itself using homebrew and oh-my-zsh afterwards via the wget. It's kind of silly that oh-my-zsh isn't just in homebrew.

Avatar

'resource' is the model that gets checked. Ryan's example is that you can only edit a topic if you created it. So, resource would be the Topic model.

Watch around the 5:00 mark.

Avatar

Thanks Ryan! But in paypal IPN docs, it says you must have to return the exact messages (properly encoded) in response within 30 seconds. Otherwise, it will send it again (with the assumption that previous message was not delivered to the listener). I'm confused!

Avatar

A new-bee here. Can someone kindly explain what the 'resource' argument refers to. I am reading the code and I know what 'controller' and 'action' are referring to, but I am clueless about the 'resource' being passed as an argument stands for.

Many thanks.

A link to the code on railscast repo: http://bit.ly/TceGen
app/models/permissions/base_permission.rb

module Permissions

  class BasePermission

   def allow?(controller, action, resource = nil)
   end

   def allow_param(resources, attributes)
   end

 end

 def permit_params!(params)
 end

end
Avatar

I'll second the rails_config comment. I've been using it (in projects for two separate clients), and it does pretty much exactly what I want. It allows for default settings, environment-specific overrides, and local (i.e., not checked-in) overrides. As with the final approach in Ryan's screencast, it makes the config settings available in a global.

There are certainly edge cases where it might not work well, but for my uses (passwords, email configuration, API keys, and the like), it's cleaned things up considerably.

Avatar

Base on this example, How do we delete an entire survey together with it's questions and answers? Please help...

Avatar

That's a really simple and interesting idea. Why isn't this more popular? I like it!

Avatar

Exactly, although I put application.yml in Capistrano's shared directory and symlink it rather than uploading it every time. That way, a developer doesn't need access to the latest production server configuration in order to deploy.

Avatar

That's absolutely true for the examples given in the screencast. However, many of Heroku's plugins depend on ENV configuration; SendGrid for example. So configuring your app to use ENV in those cases allows you to use Heroku's configuration in production and your own locally.

Avatar

I just ran into this problem again..

I ended up changing the script in recipes/rbenv.rb, the line that runs the bootstrap to:

run %q{sed "s/sudo/sudo -p 'sudo password: '/g" $HOME/.rbenv/plugins/rbenv-installer/bin/rbenv-} + rbenv_bootstrap + " | bash"

I change the sudo to the format capistrano wants and run it through bash.

Avatar

Thanks Ryan, good episode. And interesting comments with good links. One thing that I think would complete the railscast well would be the capistrano deploy script. Since you have the file in .gitignore, it will not post to the server with your cap deploy, so you just need to add a command to put the yaml file to the server when you deploy.

Avatar

Hello! Thanks for gem. But I have problem: on editing model with tags, I have empty tags field. I tried both ways of realising but also empty.

ruby
<%= form_for(@post) do |f| %>
...
    <div class="field">
      <%= f.label :tag_list, "Tags (separated by commas)" %><br />
      <%= f.text_field :tag_list %>
    </div>
...
<% end %>

I tried to print simple @post.tag_list, an it is not empty but in form it is empty( Need help.

Avatar

worked like a charm :) Thank you!!

Avatar

Can you add the Coffeescript to the show notes?

Avatar

Is there a recommended way to add events to a Google Calendar account?

Avatar

HI ryan, I am opening up your code straight from source file, how come am getting

"can't convert nil into String" ?

what do I need to do to change this?

thanks much

Avatar

Same problem here

EDIT: solved, first you need to add id and name columns to group

ruby
def self.tag_counts
    Tag.select("tags.id, tags.name, count(taggings.tag_id) as count").
      joins(:taggings).group("taggings.tag_id, tags.id, tags.name")
  end

then you need to coerce the count into an integer in the helper:

ruby
def tag_cloud(tags, classes)
    max = tags.sort_by(&:count).last
    tags.each do |tag|
      index = tag.count.to_f / Integer(max.count) * (classes.size - 1)
      yield(tag, classes[index.round])
    end
  end 
Avatar

Any luck with that? I am now also trying with Rails 3.1 and rack-offline 0.6.4 and also lose the css & js on development

Avatar

Hello, I have a question. If I already have my own authentication / authorization systems but I want to add the option to login with facebook, this gem could help me????

Avatar

Yeah, seems to be a problem with Chrome. On other browsers it does work for me. What browser are you using? Update: gem update jquery-fileupload-rails and clearing my cache seems to have fixed this for me.

Avatar

Minor not that may help folks if you aren't familiar with yml files (I am not) :

if you want to put your AWS account, access key, and secret access key in enviornment variables, you must use the <%= %> brackets to access them. For example :

access_key: <%= ENV["AWS_ACCESS_KEY"] %>

This is unlike other rails configuration files. I'm not quite sure why since yml files look ruby-ish.

Avatar

I have done exactly as in this episode. When I fetch translations from redis they are printed on translations page like this:

ru.items.title: ["\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435"]

I get the same if I print it to the log file. In the view with ru locale when using t('items.title') it's translated to "Название".

Avatar

I have been using Yettings which seems to work well.

Avatar

Similar issue as well. Is there any fix for this as of right now?

Avatar

Thanks so much for tackling this topic and thanks to Alan above as I had that same problem. I am actually having quite a lot of trouble with following along. First of all, and I'm not sure how important this is, my router file and my template file were both named simply entries... and index... respectively (I guess this is the price of coming to the party 10 months late, the generators may have been updated?), but where the code is right now, neither the alert in the index function, nor the display from the show function work. If anyone has any suggestions, I'd really appreciate it.

https://github.com/thegreatmichael/raffler/

Avatar

Hmmm, no file seems to be chosen once I tied my file_field_tag to the id that fileupload uses. Anyone have similar issues?

Avatar

You should also replace total_entries with total_count.

Avatar

Thanks for the great article! I'm using redis and translations view for my russian ("ru") translations. The problem is, in the translations#index view my translation values look like escaped unicode entities:

ru.foo: [\u041d\u0430]

while when I use t('foo') in my views the value is output properly. With English translation everything is fine of course. Does anyone know what could cause that "broken" output in translations#index view?

Avatar

I'm trying to use mongoids versioning system (also looking at mongoid-history) but am having difficulty figuring out a basic undo and list of versions.

Are there any good tutorials out there on this?

Avatar

I use the JQuery file upload (but just allowing one file to be selected). If the file is just part of a object, say user. So the user can upload a single picture to the user object. I don't want to create a new record when a file is uploaded, simply update a field. How does one accomplish that?

Avatar

why does the line @haiku.add_or_update_evaluation(:votes, value, current_user) generate the error:

undefined local variable or method `user'

ruby
def vote
    value = params[:type] == "up" ? 1 : -1
    @haiku = Haiku.find(params[:id])
    @haiku.add_or_update_evaluation(:votes, value, current_user)
    redirect_to :back, notice: "Thank you for voting"
  end

application controller:

ruby
  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user

How can this be corrected?

Avatar

You mention (@7:10) that if you're not using Heroku, you don't use environment variables.

Wouldn't the CONFIG hash solution work on Heroku also? If Heroku itself were looking for a setting in the environment variables, that would be a reason to use environment variables. In all of the screencast examples (auth & mail settings), we have control of both the definition and usage of the configuration method.

Avatar

If you use Heroku, it makes sense to use foreman in development. If you do that, you can put all your config vars in a .env file.

https://github.com/ddollar/foreman/blob/master/lib/foreman/cli.rb#L134

Avatar

I find this configuration very useful as well. Further, I prefer to add a defaults section to the YAML config file, and allow let the other sections to inherit from that.

yaml
defaults: &defaults
  email: info@example.com

development:
  <<: *defaults
  email: me@example.com

test:
  <<: *defaults
  email: test@example.com

staging:
  <<: *defaults

production:
  <<: *defaults
Avatar

In Rails 4 the cookies are secure by default when you use force_ssl in your application configuration. https://github.com/rails/rails/commit/d6933a1e9fdce873e5540813f4d44d313b6d363d

Avatar

Since Ruby is an interpreted language, what is the drawback to storing configurations/settings in a simple ruby hash in an rb file/Ruby module and then include the file/module? What advantage does parsing a YAML file into a simple ruby data structure yield since Ruby is already pretty darn readable?

I know you could make arguments that you might include your real config file in version control, but that's true for YAML et al. as well.

Avatar

great! I just made a minor adjustment so that it adapts the twitter bootstrap framework's icons

ruby
def sortable(column, title = nil)
        title ||= column.titleize
        css_class = column == sort_column ? "current #{sort_direction}" : nil
        direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
        link_to "#{title} <i class='#{direction == "desc" ? "icon-chevron-down" : "icon-chevron-up"}'></i>".html_safe, {:sort => column, :direction => direction}, {:class => css_class}
end
Avatar

Great episode. I've followed it to the letter, and the datepicker appears, but the options to the datepicker aren't taking effect. I've looked carefully at ordering, and the output javascript file which looks great with options present. I can repost with more code if desired. I am also using twitter-bootstrap-rails and jquery-fileupload-rails gems and wonder if those might be causing conflicts. This should just work. Thanks!

Avatar

If you are using foreman, you can put env vars in .env file. Also, there is a dotenv gem worth checking out

Avatar

This speakerdeck presentation by Matt Sanders dives even deeper into ActiveSupport::Notifications, and is an excellent companion to this Railscast.