RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

any solution? I'm looking to implement the same thing

Avatar

This is not a solution for your specific problem, but I'm performing the same integration using the gem 'paypal-sdk-rest' which helps to connect to the Paypal REST API.

With this gem you can create a Payment using the payment_method: 'paypal' which behaviour is similar to the express checkout of the classic API.

This is a simple working test code, hope it helps:

Into a controller:

def test
p = PayPal::SDK::REST::Payment.new(
{
intent: 'sale',
payer: {
payment_method: 'paypal'
},
redirect_urls: {
return_url: paypal_return_url,
cancel_url: your_cancel_url
},
transactions: [
{
amount: {
total: '1',
currency: 'USD'
},
description: "Test item'
}
]
}
)
if p.create
redirect_url = p.links.find{|v| v.method == 'REDIRECT'}.href
Rails.logger.info "Paypal Payment ID: #{p.id}"
Rails.logger.info "Redirect to: #{redirect_url}"
redirect_to redirect_url
else
Rails.logger.info p.error.inspect
end
end

def paypal_return
p= PayPal::SDK::REST::Payment.find(params[:paymentId])
# at this point p.state == 'created'
if p.execute(payer_id: params[:PayerID])
if p.state == 'approved'
redirect_to your_success_path
else
redirect_to your_failure_path
end
else
redirect_to your_failure_path
end
end

Avatar

To anyone who is looking for an easy Rails plus Angular setup, the gem Entangled might help. It's very easy to integrate and is basically ActiveRecord for Angular. It also syncs all changes to your database in real time across all connected clients.

https://github.com/dchacke/entangled

Avatar

Hello,
in 2015, There are some new issues in your encrypted paypal button.

Since december 2014, Paypal security is using TLS and no longer SSL due to its recent vulnerabilities.

So what will be the new ruby Syntax and/or configuration for encrypting paypal form button in your function "encrypt_for_paypal(values)" ?

Avatar

how to upload multiple files using carrierwave
hi
i am using carrierwave gem for file upload. It is working fine with single upload, but how to upload multiple files please help me.

This is my form:

<%= form_for(@invoice_detail , html: {class: 'form-horizontal', role: 'form' }) do |f| %>
 <div class="field">
        <%= f.label :invoice_number, :class => 'control-label' %>
            <div class="controls">
    <%= f.text_field :invoice_number, :class => 'text_field', :required => true, :maxlength => 15, :placeholder =>'15 Alpha Numeric with special Characters', :presence => "check invoice num"   %>
  </div>
  </div>
  <div class="control-group">
      <%= f.label :attachment, :multiple => true , :class => 'control-label' %>
      <div class="controls">
        <%= f.file_field :attachment, :class => 'file_field', :required => true %>
      </div>
    </div>
    <div class="form-actions1">
    <%= f.submit  :class => 'btn btn-primary' %>
    <%#= f.submit "cancel", :class => 'btn btn-danger', method: :delete, data: { confirm: 'Are you sure you want to cancel' } %>
    <%= link_to "Cancel", invoice_details_path(), :class => 'btn btn-danger', data: { confirm: 'Are you sure you want to cancel' } %>

  </div>
<% end %>

attachment_uploader.rb:

class AttachmentUploader < CarrierWave::Uploader::Base

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  def extension_white_list
    %w(xlsx pdf doc htm html docx png jpg jpeg xls)
  end

  def filename
  "#{model.invoice_number}.#{file.extension}" if original_filename.present?
end

end

I used http://richonrails.com/articles/allowing-file-uploads-with-carrierwave for refernce.

Avatar

I'm getting the following error when I load any page of my app:

undefined method `scope_schema' for nil:NilClass when users session creation
any body have idea about this

Avatar

While Ryan is on his Sabbatical, I think it important to keep some of this information up-to-date with the changes. Ryan developed a well-deserved reputation and his RailsCasts are referenced just about anywhere you can google a rails problem/solution.

As such, I want to comment on a couple of things regarding this episode.

The strong_parameters gem is automatically implemented in this episode. This is confusing because the docs for s_p shows controller-level checking, which has now become the standard for all Rails 4 apps.

You may notice that there isn't a method permitted_params inside the application_controller. All whitelisting logic has been moved to the application controller via the authorize method, which calls current_permission. All strong_parameters checking is now handled by base_permission.rb inside the permit_params!(params) method and delegated to each of the permission classes - Admin, Member and Guest.

I found it very advantageous to rename some of Ryan's code. In the video, he recommends renaming the allow method to allow_action. DO THIS. Also, I took the liberty of renaming the allow_param method to allow_attribute, since that is what is being allowed and it removes identity confusion with the params hash.

All-in-all, this is a great starting point for any Rails-based app. All you need to do is fork the code from GitHub, include the rename gem to change the name of the app, and start building your models. For each model you include, go back and whitelist the appropriate attributes (model fields) with the appropriate authorizations (admin, guest, etc.) Voila! Instant authorization including mass-assignment protection.

Now, just pop on over to RC#250 (revised) and roll your own authentication. Both episodes merge without problems. Now you have a fully functional template for building just about anything.

Avatar

Mark. I literally almost went nuts. 2+ hours just trying to get the card to push up to stripe. Turbolinks was my issue. Thank you so much.

Avatar

Whoever watches this and prefers pushing over polling, check out https://github.com/dchacke/entangled

Entangled is a Rails gem that pushes data changes to all clients in real time. Maybe it helps someone!

Avatar

How did you end up solving the aggregation problem?

Avatar

Hello migane,

Do you have any updated information on highcharts as this comment was made 3+ years ago? Thank you, BBa

Avatar

100.times
puts "*********Thank You************************"
end

Awesome Job

Hats off Ryan.

Avatar

params doesn't return all of this now (Rails 4.2). params only returns the action and controller and an id if applicable.

What do you do now? Parse the url?

Avatar

So this railscast is great but I ran into problems with the config/initializers/doorkeeper.rb file. Instead of getting to the authorization pages I was redirected to the provider site homepage. I was able to fix this by using all the code shown here
LINK

Avatar

find_all_by_complete.... is not working for me..
can u please tell me what might be the problem...

Avatar

can someone help me?

How is it possible to add the filename as a new column in the database?

Avatar

I am pretty sure I had the same problem. In your _condition_fields.html.erb did you make sure to surround everything with:

<div class="fields">
</div>

It is triggering on that div I believe.

Avatar
ruby
<%= f.hidden_field :product_type_id %>

should be

Avatar

Have you inserted

ruby
<%= f.hidden_field :tracker_type_id %> 

in the app/views/products/_form.html.erb

Avatar

You have a wrong gem, the correct gem is:

ruby
gem 'foundation-rails'

And not:

ruby
    gem 'zurb-foundation'
Avatar

hello all, with rails 4, I could not pass the locals variable to the template handler : only the hask key was present in the strings array named template.locals
I created a rails github issue for that :
https://github.com/rails/rails/issues/19204

Avatar

Just ran into this as well. Anyone found a decent workaround?

Avatar

For people following along with the code in this Railscast, the curl command has changed. Github redirects the 'raw.github.com' to 'raw.githubusercontent.com' now but the curl command doesn't follow the redirect.

curl https://raw.githubusercontent.com/janl/mustache.js/master/mustache.js > vendor/assets/javascripts/mustache.js

Or if you don't trust me (you shouldn't), then tell curl to follow redirects with the -L option and use Ryan's curl command instead:

curl -L https://raw.github.com/janl/mustache.js/master/mustache.js > vendor/assets/javascripts/mustache.js
Avatar

There's no such thing as online users. One possible way would be to subscribe all users to a broadcast channel, and send them a message making them ping your server.

Avatar

Check out how I load YAML file config for a basic http authentication in my tutorial
http://aflexsystem.com/how-to-create-a-simple-admin-control-panel-with-ruby-on-rails-in-less-than-9-minutes/

You can use

ruby
if File.exists?(File.expand_path('../application.yml', __FILE__))

to check if the file exists first.. and set your heroku variables manually

Avatar

I just wrote a gem to implement real time behavior in a Rails app à la Firebase: https://github.com/so-entangled/rails

I was hoping to make it a little simpler than private pub - I'd greatly appreciate your feedback!

Avatar

Also the new.js.erb title incorrectly has the view/templates directory and should be /app/views/tasks/new.js.erb instead of /app/templates/tasks/new.js.erb

e.g.

/app/views/tasks/new.js.erb
$('#new_link').hide().after('<%= j render("form") %>');
Avatar

Sounds as though you're phishing for their facebook password. I see where you may be coming from but answering this question would possibly lead to questionable behavior. Sorry, man.

Avatar

Checkout

ngrok.com

Once setup, running a subdomain is as easy as:

ngrok -subdomain=mysubdomain 3000

https://mysubdomain.ngrok.com -> 127.0.0.1:3000
http://mysubdomain.ngrok.com -> 127.0.0.1:3000

I used it to test PayPal's IPN for recurring subscriptions.

Avatar

Checkout

ngrok.com

Once setup, running a subdomain is as easy as:

ngrok -subdomain=mysubdomain 3000

https://mysubdomain.ngrok.com -> 127.0.0.1:3000
http://mysubdomain.ngrok.com -> 127.0.0.1:3000

I used it to test PayPal's IPN for recurring subscriptions.

Avatar

Hello all, I'm currently following this guide and I'm running into a problem with the first remove answers step.

<%= f.label :content, "Answer" %>
<%= f.text_field :content %>
<%= f.hidden_field :_destroy %>
<%= link_to "remove", '#', class: "remove_fields" %>

jQuery ->
$('form').on 'click', '.remove_fields', (event) ->
$(this).prev('input[type=hidden]').val('1')
$(this).closest('fieldset').hide()
event.preventDefault()

when I go to test this and click on the "remove" link nothing is hidden. when I submit the form it doesn't remove the answer. Any thoughts?

Avatar

As a general question Ryan, do you rehearse these until you can get them in one session or do you do a lot of edits. Just curious.
Or maybe you are just that good at it?
Either way tanks! Oops! Do you have a screen-cast showing how to use the new Rails4 error console?

Avatar

I want to get response from this event method using rest client. It does not response. Is the Redis subscribe method create any problem for Restcleint ? I make question in here also http://stackoverflow.com/questions/28485446/rest-client-not-working-for-rails-server-sent-eventsse

Avatar

Alan - the issue was in the product_types_controller, but your solution is in the products_controller. There might also be a problem in the products_controller, but initially, since product_types contains the :fields_attributes hash, the solution needs to be in permitting params[:product[:fields_attributes]] or somesuch. I notice the solution link you gave from stack makes the same mistake. Or, is it a mistake?

Avatar

I've added all of the code up untill about 3:30 min in and it's successfully uploading the csv file but the rows aren't getting associated with a user.

I'm really struggling to figure out how to get this to work. Any help will be appreciated!

I've posted a full description of the issue to stack overflow.

http://stackoverflow.com/questions/28347026/associating-rows-from-uploaded-csv-files-with-a-user-in-rails

Avatar

Mind you: In rails 4 dont use attr_accessible in the model, instead in the controller add:

ruby
   private
    def post_params
      params.require(:post).permit(:title, :intro, :content, :user_id, :tag_list)
    end

ehh this took me an hour to figure out :)

ps: nice to add this in the modell though:

ruby
  validates :tag_list, presence: true
Avatar

how can I use will_paginate with ajax for this.

Avatar

You need to install curl and make sure curl.h is available to your compiler path.

Avatar

How deploy that?
What specify in deploy.rb or how call lib/taks/resque.rake

Avatar

*** very frustrated... want to use this and it is now feedjira and these issues are all over the internet with no solutions>>> please help... thanks

$ gem install feedjira
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing feedjira:
ERROR: Failed to build gem native extension.

c:/RailsInstaller/Ruby2.0.0/bin/ruby.exe -r ./siteconf20150131-33384-bj8eh2.rb extconf.rb

checking for curl-config... no
checking for main() in -lcurl... no
*** 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.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=c:/RailsInstaller/Ruby2.0.0/bin/ruby
--with-curl-dir
--without-curl-dir
--with-curl-include
--without-curl-include=${curl-dir}/include
--with-curl-lib
--without-curl-lib=${curl-dir}/
--with-curllib
--without-curllib
extconf.rb:18:in `': Can't find libcurl or curl/curl.h (RuntimeError)

Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
options to extconf.

extconf failed, exit code 1

Gem files will remain installed in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/curb-0.8.6 for inspection.
Results logged to c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/extensions/x86-mingw32/2.0.0/curb-0.8.6/gem_make.

Avatar

Don't miss a better alternative: Que.