RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

When you use a command like:

*.rb
UserMailer.signup_confirmation(@user).deliver

does .deliver return a result? That is, is:

*.rb
result = UserMailer.signup_confirmation(@user).deliver

valid code, and what, if anything, gets returned. I'm trying to figure out a way to catch an error if the smtp server is down.

Avatar

If anyone is stuck on this:

$().live is not a function - JavaScript/jQuery

I solved it by switching 'live' to 'on'. Seems like the live-function is a little bit outdated.

Avatar

I was curious how this setup compares with using MiniTest or how much faster MiniTest and MiniTest Spec would be when using some of these gems and techniques.

Avatar

I could not get the code provided by Ryan to work until I added the line
Faye::WebSocket.load_adapter('thin')

to my faye.ru file.

Avatar

Nice screencast!

But I am confused. If some user logs in via Twitter,and the later via Facebook, you're stuck with two user accounts.

There must be a way to connect multiple authentication methods to the same user profile. I looked at the mapping thing and even paid for a plus account, but as of yet I don't see a good way to do this.

If the twitter account has a@b.com and the Facebook account has x@y.com, how will the merge safely?

I am thinking of making the users signup via the devise standard method, and then be able to add the other methods later (by authenticating against devise/database) - say, linking their twitter and google and facebook accounts against the devise/database accounts, but that seems less friendly.

Especially if someone is presented with the engage screen, and chooses to authenticate with an account not yet linked to their main account, how will they merge/link? By presenting them with another standard devise/database log in form?

I might be missing the whole point of engage authentication, so if anyone has a good way of doing this, I would be grateful.

Avatar

Hello everybody,

My questions:

  • What is the difference between a rails resource and a rails model?
  • Why does Ryan choose to generate a rails resource in this tutorial instead of a model?
  • How come when a resource is generated, it still creates a model file?

Thanks for any help guys.

Kurt

Avatar

How do we write a simple ruby code that should run on index page despite of its scopes, it should just run,i know its too lame to ask, but dint find anywhere :( do help ..actually i wnat to save a value in session variable , but the session value is set when scope returns some records else it doesnt

Avatar

Hi, How do I test this using rspec?

This part>

authenticate_or_request_with_http_token do |token, options|
  TOKEN == token
end
Avatar

Everything works for me as it should, locally. When I push to heroku, the add question button does not work... It just redirects me to the '#'. I am having issues with it randomly locally, but if I change the class name in the js and helper to 'add_field' from 'add_fields', everything seems to work fine.

First I had an issue with the page caching and every question and answer was created twice.

3 days of troubleshooting now. Good technique, but Cocoon may be the way to go with this one.

Avatar

"<%= form_tag projects_path, :method => 'get' do %>
you need an equal sign for rails 3
<%=
instead of
<%"

maybe for situations like that you should add some changes for different rails versions in notes? to show how it was in rails 2 and how it is in rails 3 (in case if it is a small change only ?)

anyway, great tutorial, as all of them, thanks!

Avatar

please after every thing i was unable to edit my app content

Avatar

I've got everything working except parallel in guard. I have zeus running parallel and zeus working within guard, I've added the parallel: true to my guardfile.

Would this be an issue with guard, guard-rspec or parallel_tests? What versions of these gems should I be running?

Avatar

Great railscast.

I had problems getting zeus and guard working nicely together until I found that I had to upgrade guard-rspec to 2.1.0 or greater

ruby
gem 'guard-rspec', "~> 2.1.0"
Avatar

solved by install nodejs from source

Avatar

If I'm using hstore and implementing the shirt_sizes example, how would I go about "handling the serialization manually" as suggested?

Avatar

This answer helped me out a ton. My problem occurred when upgrading from Rails 3.2.12 to 3.2.13. The fix is to specify paramName.

Avatar

Thank you for this screencast, Ryan!

Avatar

Please ignore the above question I can't seem to find an edit button. The issue was from another gem.

Avatar

Something like this worked for me:

def initialize(user)
    allow :home, :index
...
allow "devise/sessions", [:new, :create]
    allow "devise/registrations", [:new, :create, :destroy]      
    allow_param :user, [:name, :email, :password, :password_confirmation, :remember_me]
if user
        allow "devise/registrations", [:edit, :update, :cancel]
        allow "devise/sessions", [:destroy]
...
allow_all if user.admin?
end

Hope this helps

Avatar

How is it possible to use that with nested attributes (forms). I have my models defined as follows:

class Timesheet < ActiveRecord::Base
  belongs_to :user
  has_many :activities, dependent: :destroy, inverse_of: :timesheet
  has_many :time_entries, through: :activities
  accepts_nested_attributes_for :activities, allow_destroy: true
end

class Activity < ActiveRecord::Base
  belongs_to :timesheet, inverse_of: :activities
  belongs_to :task
  has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :activity
  accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? }
end


class TimeEntry < ActiveRecord::Base
  belongs_to :activity, :inverse_of => :time_entries
  validates :worktime, presence: true, inclusion: { in: [0.5, 1] }       
  validates_presence_of :activity     
end

Actually it does not work. As far I could see at Ryan's strong_parameters rails casts github https://github.com/railscasts/371-strong-parameters, he managed to do that (not very dynamically as he said and only for one post). In my case I have 1 or more activity with 7 time_entries each. Any idea how to do that? Thank you.

Avatar

Fails if there is more than one nested resource. In my case I have: Timesheet-> accepts_nested_attributes_for :activities, Activity -> accepts_nested_attributes_for :time_entries. In permission file I declared it as follows:

        allow_param :timesheet, [:status, :user_id, :start_date, :end_date] 
        allow_nested_param :timesheet, :activities_attributes, [:task_id]
        allow_nested_param :activity, :time_entries_attributes, [:workdate, :worktime]

Nevertheless, I always get the error that time_entries attributes is empty. Any idea ? Thanks and regards

Avatar

I would love an extension of this cast. Pro maybe.

Avatar

I've used this code to try to get my search working using keyup. And I get an error in the console Uncaught SyntaxError: Unexpected token }

I literally cut/paste the code and changed the id name to patient_search.

Am I doing something wrong?

Avatar

This is a great railscast and I'm hoping to use this with States/Cities.

I'm still a bit new to rails and I don't understand the associations between the states and cities.

Say for instance I select the state of TX. I'd want only Houston, Austin, San Antonio, etc to show up. If I have a State and City model, how would I tie only those cities to the state.

I figured I could do
City.rb
belongs_to :state

State.rb
has_many :cities

And then put a state_id in the City model for the relationship.

But that would be a lot of manual work to get that done. Is there any way around this or a seed file that exists?

Avatar

Stripe is awesome but they don't accept eChecks, yet. Is there another option that will allow ACH payment processing?

Avatar

My mistake, I found that I was pulling an association in the partial, which wasn't included on the order method.

Updated to Book.order("name").includes(:authors) and it works like a charm! Way smoother.

Avatar

I'm creating a CRM app where I'd like to have a dashboard that displays a feed of customer notes that were added and when. Looks like this gem will be helpful. I can see it being a lot of hits to the db if activity is heavy but I think it's worth a try.

Thanks for another great Railscast!

Avatar

I have a problem i have got the ancestry working but i cannot get the nested_messages helper to work as i keep getting the following error

undefined method `map' for #ActiveSupport::SafeBuffer:0x37c4c28
NoMethodError in Emails#index

6:
7: <%= button_to 'New Email', new_email_path, method: 'get', :class => "btnNew1" %>
8:
9: <%= nested_emails render @emails %>
10:
11:
12:

Avatar

Works great!
In chrome however it seems to 'stutter' or 'jump' when it loads more. I've removed all other css, trying to rule any wierdness out.

It does work perfectly in Firefox however. I disabled any extensions as well. Other sites like facebook.com or fab.com are super smooth in chrome, is this normal using this method?

Avatar

Integration Tests are always going to be relatively slow, as you have to wait on the actual request/response cycles and page rendering, which is a lot more overhead. While there is some stuff you can do to dull the pain, practically you may want to stick to running javascripty tests on Travis or another CI if you aren't making active changes to the feature in question. (IE, run your focused tests, and let the CI build tell you if you broke something unintentionally)

Avatar

I'm probably too late to help, but for anyone else wondering... ghostscript is your friend here. Quality can certainly be an issue like you mention in a later post. So what I do is create an intermediary image rasterized at 288 dpi (with -r 288) - I like to use png for this. Then convert that to a thumbnail or whatever in any format with imagemagick. I like to use png because if you say have something with white letters you can then use imagemagick to convert the transparency to black or something so the white letters will be visible - I've encountered this with some eps images.

Imagemagick delegates rasterizing to ghostscript, but I find it's better to just cut out the middle man and create a high dpi image that can be more easily manipulated with imagemagick directly. Postscript is a pain, but if you have to use it then ghostscript is the right tool for the job - at least the first part of it.

Obviously I share Ryan's love/hate relationship with imagemagick.

P.S. magick bindings suck - I always use a wrapper or system calls.

Avatar

Thanks for the tip.

I tried to ommit username and password, and I'm still getting the "no password supplied" error when I try to scaffold a model.

Any idea what to try next?

Avatar

I'm throwing an error trying to recreate this example. Instead of products, I am using forms. Any help or explanation would be very helpful, because this is over my head, but i'd like to learn what is going on here.

NoMethodError in Forms#new

Showing /Users/Admin/Documents/development/form_builder/app/views/forms/fields/_text_field.html.erb where line #3 raised:

undefined method `human_attribute_name' for OpenStruct:Class
Extracted source (around line #3):

1:
2: <%= f.label field.name %>
3: <%= f.text_field field.name %>
4:
Trace of template inclusion: app/views/forms/_form.html.erb, app/views/forms/new.html.erb

Parameters:

{"utf8"=>"✓",
"form_type_id"=>"3"}

Avatar

I'm having trouble because heroku is requiring the "www." subdomain.

I am having success with pow locally, but when I try to go to the URL in production it fails and the browser can't resolve the URL.

has anyone else encountered this?

Thanks!

Avatar

Spree:site no longer works but this does

rails g spree:install

Avatar

I have this test which is taking 5 seconds to run:

ruby
  describe "GET /event/id" do
    it "allows flagging an event", js: true do
      create(:recording, event: user_event)
      visit event_path(user_event)
      page.should_not have_content("Unflag")
      click_link "toggle_flag"
      page.should have_content("Unflag")
      user_event.reload.flagged.should be_true
    end
  end

How would I speed up a test like that? -- I'm using poltergeist with phantomjs and all js: true tests are painfully slow :(

Avatar

Same here under 3.2.13. The temporary workaround until this bug fix is released is to use file_field_tag instead -

<%= file_field_tag :image, :multiple => true, :name => "painting[image]" %>

Pardon my affection for the old hash syntax.

Avatar

for those having 'undefined' tasks on the list in their example, change the addtask function to the following:

function addTask(line) {
$('#tasks').append('' + line.task.name + '');
}

Avatar

I'm trying to set up my tmuxinator config file to start zeus before it runs zeus c, zeus s in my panes.

Adding zeus start to the pre: config fails, because Zeus prevents tmux from loading.

I tried starting it as a daemon with zeus start &, but zeus tries to refresh the screen, which screws up the tmux display.

How did you work with this?

Avatar

class Permission
def initialize(current_user)
allow :index_page, [:index]
allow :static_pages, [:about, :contact]
allow :sessions, [:new, :create, :destroy]
allow :users, [:edit, :update]

def allow_all
  @allow_all = true
end

def allow(controllers, actions)
  @allowed_actions ||= {}
  Array(controllers).each do |controller|
    Array(actions).each do |action|
      @allowed_actions[[controller.to_s, action.to_s]] = true
    end
  end
end

end
end

but there is something wrong
NoMethodError in PrimaryPagesController#index

undefined method `allow' for #Permission:0x007fcaee54a310
Rails.root: /Users/freshlhy/rails_projects/first_app

Application Trace | Framework Trace | Full Trace
app/models/permission.rb:3:in initialize'
app/controllers/application_controller.rb:12:in
new'
app/controllers/application_controller.rb:12:in current_permission'
app/controllers/application_controller.rb:20:in
authorize'

Avatar

Oh man that's great. I feel the reason that ryan chose to focus on Rspec in this episode is that it is still widespread in most existing applications. And, the rails core team took minitest out of rails 4 for the time being.

I'm using minitest spec in my latest application, the tests are blazingly fast.

Avatar

Hi Martin,

I have multitenancy setup as per this railscast and have just started to learn Minitest Spec. Would you mind sharing some of your testing code to show how you implemented multitenacny testing?

Thanks.