RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

I have been going through this railscast but can't seem to get the search results to actually display. When I click on the search button, the log shows that it is doing the search, but the only thing that appears on the view is the heading for the Show page (Search Results). The partial for searches (_product.htlm.erb) does not appear to even be accessed.

Any ideas?

Avatar

How did you make the HTML entities appear? I'm guessing you didn't used simple_format.

Avatar

For my app, my models are Feature instead of Book, Tag instead of Author and Tagging instead of Authorship.

I must have made a mistake:

I'm getting an error NameError in FeaturesController#create of uninitialized constant Feature::Tagging

and under the trace:
app/models/feature.rb:33:intag_tokens='`
app/controllers/features_controller.rb:66:increate'`

Has anyone else made this mistake?

Thank you,
Doug

Avatar

Another usage tip. To make creates work (e.g. when using accepts_nested_attributes_for), you'll need serialize :properties, ActiveRecord::Coders::Hstore in your model (assuming your hstore field is called "properties").

I've seen suggestions that this need will go away with Rails 4.0.

Avatar

btw it happens only with the resources path like this. when I visit post views

ruby
resources :posts do
    resources :comments
  end
Avatar

Thanks Ryan, I was wondering if you guys know why I keep getting a: "CreditCard is not defined" error? Even after following your tutorial word for word.

http://stackoverflow.com/questions/11396650/why-does-jasmine-ruby-not-find-my-js-class

Avatar

We had the same error described above in a legacy App, but the cause was that the XML is sent with an extension of XLS not XLSX.

Changing the extension to .XLSX solved it for us.

Avatar

I agree with this 100%. While I'm sure many will find Devise great (and Ryan's screen cast to back it up), I myself find that authentication is so easy in Rails that I just don't need Devise.

And the has_secure_password works great.

lol. On a different note...anyone here ever do the same time with Spring and Java? OMG what a chore.

Avatar

Great episode! Does anybody know how to set the actions field as mentioned on https://developers.facebook.com/docs/reference/api/post/ when submitting a post to the users feed.

Avatar

yes, you are quite right. the version numbers where transposed. sorry about that That version supports a considerable amount of the ECMA-376 specification - also known as office open xml. what did you use to generate your data that opened raw xml? I think you'll find axlsx to actually work. we've been sucessful in interop with Numbers and LibreOffice and expect to release google docs operability this week.

Avatar

Hi! I have the following problem: When I navigate across the site my locale changes to default. For Example when I am on index page and hit wookie and then go to another page my locale changes back to :en. I just can't get why?

my model is:
``` class Post < ActiveRecord::Base

attr_accessible :text, :title

translates :title, :text

validates :title, :presence => true,
:length => { :minimum => 5 }
has_many :comments, :dependent => :destroy

class Translation
attr_accessible :locale
end
end ```

And application controller
``` before_filter :set_locale

private

def set_locale
I18n.locale= params[:locale] if params[:locale].present?
end ```
Thanks in advice!

Avatar

As of the latest (07/07/2012) version of minitest-rails you don't need to create an Integration class and register it with MiniTest::Spec.

If you want to use Rails routing and/or Capybara matchers, you still need to include them. Like so:

ruby
Class MiniTest::Rails::ActionDispatch::IntegrationTest
  include Rails.application.routes.url_helpers
  include Capybara::DSL
  include Capybara::RSpecMatchers
end

blowmage also has a minitest-rails-capybara that obviates the need to even do the above. However, I haven't been able to get it to work as of yet. It was only released today, so there's no point in being too picky :)

Avatar

Another option is to use Vagrant, which is what I use when I develop Ruby applications on Windows.

Avatar

Don't bother trying to run Rails on Windows. I spent a few days trying to get it to work, and it just doesn't. It takes 10 minutes for Rails to start, and many gems don't work.

If you are new to Rails, trying to use Windows makes it much harder. And Rails is hard enough.

I installed Ubuntu (which can run on the same machine) which works well for Rails. Or, find an old machine and run Ubuntu on it. I ended up using sharing the source folder and using Notepad++ on my regular dev machine which works well.

The only real improvement is to get a Mac and run TextMate. But this solution is 90% there.

Avatar

Solved my own problem, i did not realize that the router acts like a controller and where i called

ruby
new Ifoundit.Routers.Entries()

I should have put the name of my router

ruby
new Ifoundit.Routers.Posts()
Avatar

I am still having the same issue as stated above

ruby
(function() {

  window.Ifoundit = {
    Models: {},
    Collections: {},
    Views: {},
    Routers: {},
    init: function() {
      new Ifoundit.Routers.Entries();
Uncaught TypeError: undefined is not a function
      return Backbone.history.start();
    }
  };

  $(document).ready(function() {
    return Ifoundit.init();
  });

}).call(this);

I have set everything to the book, and restarted server several times, any ideas

ruby
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require .//ifoundit
//= require_tree ../templates/
//= require_tree .//models
//= require_tree .//collections
//= require_tree .//views
//= require_tree .//routers
//= require_tree .
ruby
window.Ifoundit =
        Models: {}
        Collections: {}
        Views: {}
        Routers: {}
        init: ->
                new Ifoundit.Routers.Entries()
                Backbone.history.start()
$(document).ready ->
        Ifoundit.init()
Avatar

The repository they have them in does not have the newest version of underscore.

go to the gems location

Ruby1.9.3\lib\ruby\gems\1.9.1\gems\backbone-on-rails-0.9.2.0\vendor\assets\javascripts

replace the underscore.js file with your new one

Avatar

I'd like to share Unicorn+Nginx configuration with preload_app and optimized deployment scripts: https://gist.github.com/3052776

Avatar

+1 - this would be very useful

Avatar

In your model you can do something like this

validates_presence_of :password, :on => :create

Avatar

Michael, will_filter is awesome, the biggest challege i face is when i try to use it with decimal data type. Could you pliz try and add a decimal container for it. It will be really nyce.
Thanks a lot

Avatar

I am the author of jasminerice ( bias warning ). I just read of the evergreen docs. The difference seems to be that jasminerice is integrated for Ruby on Rails. If you are already using rails then jasminerice is probably what you want. If you are using javascript with something else or distributing javascript packages standalone then perhaps evergreen is for you.

Avatar

I have to agree with Andy. I have had to fight Devise a lot more than I would like to and therefore, I tried Sorcery for my current project. So far, it is working out great and it stays out of my way when I don't need it. Ryan has a screencast on it. Check it out.

Avatar

Perhaps what we're getting is just a nice abstraction, and they store things quite differently behind the scenes.

Avatar

Every time I've tried Devise, I've run into some sort of use-case that it doesn't handle. My typical workflow was to waste lots of time trying to configure Devise to fit my app, then rip it out.

Now I do authentication from scratch every time.

For me, lower-level abstractions like 'has_secure_password' work perfectly. Devise not so much.

Avatar

Hello, I have to clone the image which I have created previously. I am just copying the data present at the image column into my cloned deal image column but this didn't displaying any image. The code is as follows:

Offer.rb

has_attached_file :image,
:styles => {
:thumb=> "100x100>",
:small => "150x150>",
:medium => "300x300>",
:large => "400x400>"
}

Offer_controller

def clone_deal

@deal = Offer.find(params[:id])
@attr = { :nameofdeal => @deal.nameofdeal, :value => @deal.value, :image_file_name => @deal.image,:type => 'image/png'}
@offer = Offer.new(@attr)

Offers/show.html.erb

<% if @offer.image_file_name != nil %>
<%= image_tag @offer.image(:large),:class=>"offer_deal_image" %>

<% end %>

Avatar

I'm running into the same problem - getting the mass assignment error. I have tried to comment out that line and restarted the rails server but I still get the error. The new O'Reilly learning rails book also follows this strategy and I get the same error.

Is there a step that I'm missing?

Avatar

How do you make it so when they edit their profile they don't need to put in their password to save changes? I have tried looking around to no avail for some time.

Avatar

Any one have this working with multiple models? I am trying to create audiences like on facebook, could be users, or groups, or etc.

I have tried polymorphic assoc. and have been banging my head against this for a week.

Avatar

Thank you Jakub! I was struggling debugging, hard to spot.

Avatar

hmmmm...I just put up a repo with scripts that run without the needing sudo on the deploy user, but mine aren't gemified.

https://github.com/mcmoyer/chef-istrano

Might have to follow suit and gemify them...that really makes them handy

Avatar

Hey guys, how can I get the articles using comment object?

Somethin like these:

ruby
comment = Comment.all.first
comment.article

supposing the first comment has a comentable_type as article.

Avatar

Thank you for notifying us of that discrepancy, I've corrected the transcripts.

Avatar

Excel XML is known as SpreadsheetML

FAIR WARNING:

  • SpreadsheetML file sizes will be about 3-4 times larger than native XLS files. Not really a problem for small files, but with large data sets this could eat up your system resources to generate the file.
  • SpreadsheetML will only be readable by Microsoft Office. Other mainstream office suites will open it as an XML document.

The CSV approach fits my needs 9 times out of 10. However if you require a native Excel format, please use a gem and avoid using the SpreadsheetML method.

Avatar

In general I find using a csv view template to be more useful that a to_csv method in a model.

The problem with the view template is that the file will be downloaded with the last component of the URL as the name.

For example from a Show action with a URL like /posts/2.csv you'll get a file called 2.csv, which is not very friendly

Clinton Nixon has a nice solution in this stackoverflow post

http://stackoverflow.com/questions/94502/in-rails-how-to-return-records-as-a-csv-file

He creates a render_csv method in the application controller that adds headers to the response that use either the user supplied filename or defaults to the action name

For example, this produces a file called 'myfile.csv'

ruby
   respond_to do |format|
      format.html
      format.csv {
        render_csv('myfile')
      }
  end 
Avatar

Numbers '09 version 2.1 (436) ... should be the latest (did you transpose 1 and 2?)

Avatar

Hi, I followed the tutorial step by step and I get:
can't convert nil into String error when I click the sign in with facebook link.

I forked the source code and It does not work either.
I get the same error.
How can I solve this?

Avatar

Is there a way to put ENV variables in a file?
How does the ENV hash work?

Avatar

I was wondering when someone was going to mention that, and how much weight should be given to the author's advice...

Avatar

I was wondering when someone was going to mention that, and how much weight should be given to the author's advice...

Avatar

I've been getting this error when trying to run the cap rubber:create_staging command. It runs for 20 minutes or so successfully, but breaks when it gets here:

executing "cd /mnt/EvrlistSite-production/releases/20120706050602 && bundle exec rake RAILS_ENV=production db:migrate"
servers: ["production.evrlist.com"]
[production.evrlist.com] executing command
** [out :: production.evrlist.com] rake aborted!
** [out :: production.evrlist.com]
** [out :: production.evrlist.com] FATAL: role "EvrlistSite" does not exist
** [out :: production.evrlist.com]
** [out :: production.evrlist.com] Tasks: TOP = > db:migrate
** [out :: production.evrlist.com]

Avatar

In the ASCIIcast version, when you clear out the tbody section, you have two opening tbody tags. I think you want one opening and one closing. Thanks for the great examples!