RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

With Foundation 5.0.3, I needed to follow this crazy thread to get the mixin import working: https://github.com/zurb/foundation/issues/2128. The final suggested work-around is what worked for me.

Avatar

Didn't ask it myself, but helped me. thanks!

Avatar

Hello very nice screencast but i'm stuck with a small issue hope u help me out.

In my case when i click on the links, it gets stuck on 'page loading' message forever. It does NOT refresh or render anything.

Just for your info i'm using haml not erb. So i named the file index.js.haml

I'm using latest jquery(3.0.4) through jquery-rails gem

Avatar

Hey... ... extremely late on this one - but just started a new app and needed reputation with pagination

try
@newsletters = Newsletter.approved.page(params[:page]).per_page(NEWSLETTERS_PER_PAGE).find_with_reputation(:votes, :all, order: "votes asc")

By placing the "find_with_reputation" after pagination (will_paginate) works.

Avatar

In rails 4 it seems that attr_accessible is removed from the model, and is not used any more. In general, I have difficulties getting this to work, and would have wanted to see an updated version with rails 4!

Avatar

Yep, had the same error. Thanks for helping me figure this out.

Avatar

Brunzino, did you make it with rails 4.. could you please send me the code! It will be really appreciated

Avatar

I tried it in my project but didn't work yet. for now I have an error says undefined method Klass (that existis in helper). Any help?

ps. I didn't use nifty_layout.. created model normaly

interesting cast. Thanks!

Avatar

This is an awesome tutorial!

Firefox does not seem to clear the credit card number fields before submitting (even though name: nil on each one) as I discovered CC #'s in my logfiles!

So I modified my orders.js.coffee as follows:

  handleStripeResponse: (status, response) ->
    if status == 200
      $('#order_stripe_card_token').val(response.id)
      # clear CC fields before submitting to Rails:
      $('#card_number,#card_code,#card_month,#card_year').val('')
      $('#new_order')[0].submit()
Avatar

In Rails 4 you have to add:

config.autoload_paths += %W(#{config.root}/lib)

to the application.rb file in order to avoid an error when using the interceptor.

Thanks Ryan!

Avatar

Totally agree with Robert, it is one of the best episode!!

I was following the tutorial, attempting to test out deployment with Rubber. Managed to survive from the Duplicated rules error, creating instance error, etc but I was finally stopped by the infinite connection loop:

** Instance running, fetching hostname/ip data
Trying to enable root login
* 2014-01-16 15:36:41 executing rubber:_ensure_key_file_present'
* 2014-01-16 15:36:41 executing
rubber:allow_root_ssh'
* executing "sudo -p 'sudo password: ' bash -l -c 'mkdir -p /root/.ssh && cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'"
servers: ["---.---.---.---"]
** Can't connect as user ubuntu to ---.---.---.---, assuming root allowed
* 2014-01-16 15:36:44 executing rubber:_direct_connection_---.---.---.---_673'
* executing "echo"
servers: ["---.---.---.---"]
** Failed to connect to ---.---.---.---, retrying
* 2014-01-16 15:36:48 executing
rubber:_direct_connection
---.---.---.---673'
* executing "echo"
servers: ["---.---.---.---"]
** Failed to connect to ---.---.---.---, retrying
* 2014-01-16 15:36:53 executing `rubber:_direct_connection
---.---.---.---_673'
* executing "echo"
servers: ["---.---.---.---"]
The IP is masked...
I have tried a lot of different things:

Manually connect to new instance with ssh and the key
Double check the rubber.yml to see if the key path is correct
Run the cap command in -v
Check if the instance I defined is the same as the default ami type

They all seems Correct so I think there must be something with the command used for rubber to connect and run the "sudo -p 'sudo password: ' bash -l -c 'mkdir -p /root/.ssh && cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'". However there's no where I can see what Rubber was talking to my instance. I tried to get into the source code but it lead me to no where too.

I have done quite a number of googling and it seems like it is quite a common error but no real solution to this. Can anyone suggest what's likely to be the problem? Thank you.

Avatar

Hi Lionel,
I also had problems with the migration.
Maybe this https://github.com/globalize/globalize/issues/261 could help you.
Works fine for me.

Avatar

If u have problems with the indentation on index.jst.eco
try this - >

Raffler

<%for entry in @entries.models: %>
<%=entry.get('name')%>
<% end %>

Avatar

Where do I actually get the data he uses for countries and states, and why not, cites??

Avatar

How did you deal with your form post? Was it to events_comments_path or events_pictures_comments_path?

Avatar

Rails looks at the collection object, figures out what kind of object is is, and automagically looks for a partial by that name.

For example, if the controller set us an instance var like so:
@completed_tasks = Task.where(complete: true)

Rails goes like:
So you want me to render this bad boy? What kind of instance var is that? It then figures that it is a "Task" collection, then it assumes that you must have a partial named "_task" that will display it.

Silly Rails...

Avatar

Depends on what your are trying to do in your controller tests, but here is what I did

ruby
  before do
    controller.stub(:authorize)
  end
Avatar

Is there any solutions or steps to Deploy it to Heroku ?

Avatar

I was able to use strong parameters on the create action successfully.

But unfortunately, I am getting an error from the update action when trying to save the selected winner to the database. Rails is saying "wrong number of arguments (1 for 2). I've tried many google searches to no avail, I would appreciate anyone's help with this.

Thanks!

Avatar

I was trying this in Ruby 2, with Rails 4.

The attr_attributes no longer works. Permitting the :fields_attributes didn't cut it, since there is an unknown number of fields. See this

I ended up permitting all parameters with:
params.require(:product_type).permit!

I know it's not safe to do so. If somebody knows a proper way to validate the product type params I would love to hear it.

Avatar

Thank you! Worked finally for me. One update is that I had to change

gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass'

to just
gem 'bootstrap-sass' to get it to work

Avatar

I have a similar scenario and I just create a password for every Customer

Avatar

downcase on create and when you authenticate

Avatar

What about setting a password for the user then in step 3, having the user set (change) his/her password?

Avatar

Would love to see an updated version now that scrAPI is no longer maintained.

Avatar

Oops, we are so sorry but we have solved it... it happened due to a wrong configuration on the server...

Avatar

Tomaz, thank you very much, pusher is great service, not affiliated to them too :) just used it with a free account and I am pleased.

Avatar

Hi

I have a problem with devise. Im trying to login on a custom page of my site and this redirected to the devise login page.

Im seeing into my log file and there are a line: Completed 401 Unauthorized in 2ms.

Also, I have this into my controller app file:
before_filter :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :email
devise_parameter_sanitizer.for(:sign_in) << :email
end

My log file shows this:

Started POST "/users/sign_in" for 127.0.0.1 at 2014-01-11 17:39:38 -0500
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EoIQQ/IFKP4dtaTgb5IPYJulXSIHdT3lTtE4D5viT2o=", "user"=>{"email"=>"myemail@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 2ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EoIQQ/IFKP4dtaTgb5IPYJulXSIHdT3lTtE4D5viT2o=", "user"=>{"email"=>"myemail@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/shared/_links.erb (1.0ms)
Rendered devise/sessions/new.html.erb within layouts/application (8.0ms)
Completed 200 OK in 139ms (Views: 25.0ms | ActiveRecord: 0.0ms)

I hope you can help

Avatar

I'm having the same issue. I think I have troubles with the callback URL, the new menu for Apps in Facebook is not simple and direct as the old one, so I can't find where to write the address down.

Avatar

Great tutorial.

When using the predicates :true or :false, the user shouldn't have to put anything into the value field, however the condition is dropped when you hit search. Any workaround for this?

Avatar

instead of rendering images you can do the arrows 100% in css

heres some .less that i used for decent up/down arrows

https://gist.github.com/blairanderson/8365703

Avatar

Is there a reason the personal view uses form_for @user while the social view uses form_for current_user? Since the controller sets @user to current_user, I suspect the views got created at different times and there's no real difference in this case. Though it seems like @user would be the better choice, since the controller can … control that value.

Avatar

I wish to use Doorkeeper for 3rd party authentication but wish to skip and use before_filter authenticate! for AngularJS based client side web app.
Is it possible to do this?
What is the best way for authentication for an API which should be usable for Single Sign On 1st party app and 3rd party apps like chrome extension?

Avatar

Great episode!

We have followed the tutorial and succeeded setting up multiple instances with haproxy as load balancer. We used "complete_passenger_nginx_postgres" template of Rubber.

However, uploading file (with size larger than 1MB) from browser to the server cannot reach the rails server of the app instances. It seems to be blocked from haproxy or some prior layers.

We checked nginx's client_max_body_size and it's already set to 10M.

Do you guys have any idea on this issue and how to fix it? Thank you in advance!

Avatar
app/models/messages/_message.html.erb:
<li><%= message.content %></li>

should do it.

Avatar

In rails 3 you can use where() for this scope.

Avatar

I was banging my head on how to preserve my search criteria into the CSV/XLS export. This worked great! Thanks for saving me the headache. I owe you Starbucks.

Avatar

You mention that this is not suitable for tasks that run frequently but give no indication as to why it is not suitable or even what might be suitable.

I have a need to poll for changes to the database every 2 minutes, if changes are found then add add to sidekiq worker jobs for processing.

I have a rake task that looks for the changes and handles adding to the worker queue. I would be interested to know what might be a suitable solution for running a rake task every couple of minutes in this type of frequently polling scenario

Avatar

Feather,

Thanks so much for pointing this out. I've been searched solutions for hours and finally get rid of that 406 error.

Thanks so much!!

Jay Kan

Avatar

I get an issue when I include validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i in app/models/message.rb. If I replace it with /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i (found at Contact us functionality in Rails 3 - answer from JJD) it seems to work.

The error I receive says "The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?"

Note* I am using Rails 4 - not sure if it makes a difference. Does anyone else have this problem?