How do I run multiple lines of Ruby in html.erb file

If you need extra functions in your view, you normally declare those inside a helper. For each controller, if there is a helper it is automatically loaded. For instance, if you have a PeopleController, in the app/helpers folder, there should be a people_helper.rb, and it should look like this module PeopleHelper def name #do something … Read more

Rails 4.0 expire_fragment/cache expiration not working

I believe the issue is that when you cache the fragment in your view, a cache digest is being added to the cache key (views/all_available_releases/41cb0a928326986f35f41c52bb3d8352), but expire_fragment is not using the digest (views/all_available_releases). If you add skip_digest: true to the cache call in the view it should prevent the digest from being used. <% cache … Read more

How might I pass text data from the ruby console into my clipboard without saving to a file?

You can just echo it instead if there are no newline characters in the string; otherwise, use the IO class. Using echo: system “echo #{stringdata} | pbcopy” OR `echo #{stringdata} | pbcopy` Ruby will then just rip the text from memory, inject it into the shell command which opens a pipe between the echo and … Read more

Ruby Net::HTTP – following 301 redirects

301 redirects are fairly common if you do not type the URL exactly as the web server expects it. They happen much more frequently than you’d think, you just don’t normally ever notice them while browsing because the browser does all that automatically for you. Two alternatives come to mind: 1: Use open-uri open-uri handles … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)