RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

For everyone telling me to get a subscription. I already have one or I wouldn't have been able to comment here in the first place.

I was merely pointing out that since this is suddenly a large, important, issue which has blown up in everyone's faces maybe this one time the revised episode could go out to all in the spirit of public service.

Avatar

even though you posted this 2 years ago - you just helped me in a big way. I did the same thing. However - the first thing I looked at was: http://apidock.com/rails/Rails/Generator/Spec/klass
I was getting worried that klass was no longer available in the way it was being used. I thought it was going to be a very long night! :P But - it turned out to be a very easy fix - thanks to you! CHEERS!

Avatar

As always, your Railscasts are timed just right... just upgraded Bundler before watching this and got the fatal nokogiri build stuffs

For me, I had to do:

ruby
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

Point is, your Railscast got me in the right direction, but I needed to refer to a similar issue when previously setting up my Macbook Pro at https://gist.github.com/746966#gistcomment-80034

Avatar
module EcoTemplateHandler
  def self.call(template)
    Eco.render(template.source.inspect, template.locals)
  end
end
ActionView::Template.register_template_handler(:eco, EcoTemplateHandler)

<%= raw render "eco_template" %>

Avatar

The creation of the Category I need to pass the establishment_id how can I do this? being that he is not an attribute attr_accessible

ruby
class Product < ActiveRecord::Base

  validates :name, :description, :price, :category_name, presence: true
  validates :category, associated: true

  belongs_to :establishment
  has_one :item_carte
  has_one :category, through: :item_carte

  attr_accessible :name, :description, :price, :category_name
  
  def category_name
    category.try(:name)
  end
  
  def category_name=(name)
    self.category = Category.find_or_create_by_name(name) if name.present?
  end
end
ruby
class Category < ActiveRecord::Base

  validates :name, presence: true
  validates :name, uniqueness: true
  validates :products, associated: true

  belongs_to :establishment
  has_many :item_cartes
  has_many :products, through: :item_cartes

  attr_accessible :name
end
Avatar

I had the same problem is rails 3.2, thanks for the heads up.

Avatar

and project started!!!!
The one ryan mentioned

Avatar

I recently found that when using the method_missing trick in my base presenter class, it raises an exception when I try to use the capture method directly.

Dumb example:

ruby
class UserPresenter < BasePresenter
  def some_div(&block)
    content = capture(&block)
    content_tag(:div, content)
  end
end

This raises ArgumentError: wrong number of arguments (0 for 1)

From what I can tell, the reason is because it conflicts with Kernel::capture, maybe because Kernel always have precedence, or something.

In any case, I added a hard capture method to my base presenter class, to work around the issue:

ruby
  def capture(*args)
    @template.capture *args
  end
Avatar

Hi, I am using Ruby 1.9.3 and Rails 3.2.1 on Windows 64-bit machine. After following Ryan's step of adding gem 'twitter-bootstrap-rails' to my gemfile and running bundle, I get an error shown below. Any ideas on how to correct this please ?

Installing libv8 (3.3.10.4) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    >c:/Ruby193/bin/ruby.exe extconf.rb

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Avatar

make sure you pass "method: :delete" in your view and have jQuery.

ruby
<%= link_to 'Destroy', model_path(object), method: :delete,
        :confirm => 'Delete Model? Are you sure?' %>
Avatar

Just a small notice...

In episode notes there is
config/split_config.rb

which should be
config/initializers/split_config.rb

Avatar

Nice one!

Has someone tried to render refinerycms views throughout backbone.js like Ryan showed for "normal" Rails apps a few episodes before?

Avatar

thank you for this comment!

same here, must be a 3.2 glitch

Avatar

What should i do if i want to set max_attempts for one job to 3 and some other job to 20 ? I just started using delayed_job, so i know of only place to put such configurations (initializers delayed_job_config). But is it possible to have separate configurations per job ? for example , separate config file for mailers_job and news_letters job.

Avatar

Hey I like the idea for this and tried it on my system but something is broken. I am on Ubuntu 11.04 and when I try auto completion after rake it takes a while to load and then shows no options unless there are file names in the directory that I am in that begin with rake. Just no db:create or any thing like that. It was like this before and after I added the _rake to the custom directory. Do I need to add rake or _rake to the plugin call in .zshrc? Thanks for your help I am really enjoying your rails cast.

Avatar

It is really so nice. thank you for your share.

Avatar

@3dd13

My Procfile looks like this:
Edited after reading your codaholic_chatroom on github

ruby
#app_name/Procfile
faye: rackup private_pub.ru -s thin -p $PORT -e $RACK_ENV

WORKS NOW I CAN SECURE THE CHAT

Just wondering the difference btwn $RAILS_ENV vs $RACK_ENV

Avatar

@3dd13 could you show me your Procfile as your explanation is throwing me off a bit. Is "rakeup -R private_pub.ru" NOTE 'rakeup' a typo? Thanks.

My Procfile looks like this:

ruby
#app_name/Procfile
web: rackup -R private_pub.ru -p $PORT
Avatar

I'm wondering about this too. What is the "performance reason"?

Avatar

Thank you for this article. That's all I can say. You most definitely have made this blog into something special. You clearly know what you are doing, you've covered so many bases.Thanks!

Avatar

Thank you, Jakub!!!

I suppose I should have checked that first, but again thank you very much. Was very frustrated.

Avatar

it would really help me if there is a way to change the text_field to date_select or something in order to search db records by date.

i have a field named date among timestamps.

Avatar

You could have talked about --deployment =(

Avatar

The same is happening here, I've already installed the correct growlnotify version (MacOS 10.5.8).

Has anyone resolved this error ?

Avatar

Alright so I have finally solved this issue with help from stackoverflow. The issue is a conflict when combining jcrop with twitter bootstrap. The solution to my question is linked here. Its embarrassingly simple, apparently TBS sets image max width property to 100% and you simply override with with a style you create to remove this property. I was so focused on jcrop itself that I did ponder anything else causing the problem. Lesson learned, but I figured I would post for anyone elses benefit.

Avatar

Thanks for reporting that issue, I've fixed the link :)

Avatar

Yep, not trying to start a fight, just defending our work. Haven't tried Alchemy, never intended to say or imply anything about it.

Avatar

The page parts bug is fixed in 2.0.2. Which bug are you asking about?

Avatar

Yes. To be complete, Refinery is compatible with anything you may want. As @shaman-sh sayd, it may take some time to understand how.

I found out that browsing the source of refinery-core was explanatory.
Working with these views I've been able to restyle everything I need:

./refinery/_content_page.html.erb
./refinery/_footer.html.erb
./refinery/_head.html.erb
./refinery/_header.html.erb
./refinery/_menu.html.erb
./refinery/_menu_branch.html.erb

But most important (and I had to copy by hand) layouts/application.html.erb can make your life easier. Anyway is pretty simple (this is my version with already container-fluid class for the page_container):

html
<!DOCTYPE html>
<%= render '/refinery/html_tag' %>
  <% site_bar = render('/refinery/site_bar', :head => true) -%>
  <%= render '/refinery/head' %>
  <body>
    <%= site_bar -%>
    <%= render '/refinery/ie6check' if request.env['HTTP_USER_AGENT'] =~ /MSIE/ -%>
    <div id="page_container" class="container-fluid">
      <header id="header">
        <%= render '/refinery/header' -%>
      </header>
      <section id="page">
        <%= yield %>
      </section>
      <footer class="footer">
        <%= render '/refinery/footer' -%>
      </footer>
    </div>
    <%= render '/refinery/javascripts' %>
  </body>
</html>
Avatar

Yes, you are right. Great work on Refinery btw.

I wanted to show people some alternatives.

And to be very clear: I do not want to start a "A is better than B" discussion. I think it's great to have choice. Refinery is great in what it does, so it's Alchemy.

Avatar

Thank you Ryan.

I read the documents about upgrading bundler but after bundler upgraded to 1.1, the other dependent gems also changing. I don`t know that being any problem occur on existing project after bundler upgrading? How can i upgrade to bundler 1.1 without any problem?

Regards.

Avatar

hi Ryan,

confirm "Are you sure?" at destroy not working,
i use rails 3.2.0,
How to fix?

thx for help

Avatar

Note - this episode was written around version 0.6.x of the faye gem. If you're trying to upgrade to a current version (0.8.7 at time of writing) then you'll need to do the following:

First, add the following to your Gemfile

gem 'thin'

Second, add the following to your faye.ru file right after the require statements.

Faye::WebSocket.load_adapter('thin')
Avatar

Hi Ryan and rails cast groupies! One thing I ran into which I thought might be worth a mention:
if you develop on Linux system as I do be sure to include the gem 'therubyracer' in your Gemfile. By default refinery doesn't include it. The reason you need it is on linux there is no default JS engine. I was getting very strange behavior and lots of JS errors in my log.

Otherwise great cast!

Avatar

Hey Ryan - great as usual.

If you are using RVM to manage your Rubies they recommend not using the oh-my-zsh bundler plugin - see zsh integration with RVM.

RVM provides the functionality built in to the .rvmrc file to automatically add the project --binstubs directory to your path when you cd into the project, just follow the RVM Hook instructions on the RVM bundler page. Works automatically and no more bundle exec.

Avatar

Great stuff Ryan. Nested forms revision will be great. Use your own Gem.

Avatar

I found that for the gem provided I had to use uppercased Products otherwise I was getting an error:

/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:229:in `const_defined? : wrong constant name product (NameError).

so

rails g bootstraped:themed Products -f (worked)

P.S. Apologies for not knowing how to nicely format this as demonstrated in some of the examples above

Avatar

awesome episode, thanks for the info

Avatar

Great cast ryan. Any plans on BrowserCMS?

There is a nice (somewhat oudated) comparsion here

Avatar

Great cast ryan. Any plans on BrowserCMS?

There is a nice (somewhat oudated) comparsion here

Avatar

Also +1. I had trouble for a while trying to figure out what I might be doing wrong.

(Thanks!)

Avatar

Great RailsCast, Ryan! Thank you so much for covering Refinery CMS. It makes all the effort that we put into it just that little bit more worthwhile :-)

Avatar

Seems useful to declare that you guys actually write Alchemy CMS ( judging by that you're the two largest contributors to the project :-) )

Avatar

I m very new to ruby on rails, so can you help me.

I m getting the following error

ruby
NoMethodError in Users#new

undefined method `simple_form_for' for #<#<Class:0x5ae0f40>:0x463f218>

this is my new form

ruby
<%= simple_form_for @user do |f| %>
        
          <%= f.input :service_number %>
          <%= f.input :password %>
          <%= f.button :submit %>
          
<% end %>

this is my user controller

ruby
class UsersController < ApplicationController
  def index
    
  end
  
  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      session[:user_id] = @user.id
      redirect_to root_url, notice: "Thank you for signing up!"
    else
      render "new"
    end
  end
  
end
Avatar

Wow, what an incredibly informative episode. I learned quite a few things - especially about my troubles getting my remote production envronment to play well with bundler. Thanks!

Avatar

I had a problem with twitter-boot-strap and jcrop

The fix was to add the following to the css file

img {
max-width: none;

}

.preview{
display:block;
overflow:hidden;
}