RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Hi,

I have a requirement of sending notifications weekly for my site https://wikigurus.com/ where i need to send emails to many users at a time. Can this Batch API applicable to send requests for bulk emails?. Will it give any performance improvement?

Avatar

Hi I am trying to add miniprofiler to mysite: https://wikigurus.com/.

First I tried in my local. I am getting below error
http://localhost:53506/mini-profiler-resources/includes.js?v=ySF6M98CBehTtL86BbiEmys9yxR1HKazhe2sznfdUWQ= 404 not found.

I also added the below code to web.config

        <add path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule"  />

Why it is throwing 404 error?

Avatar

Two points to fix, I think.
One is that you create a new Cart object every time if it is not in the session. So imagine that your payment via PayPal fails for whatever reason you want. In this case you will finish to have multiple Cart records with purchased_at set to nil what is not ideal.

Another one is that you will assign first name and last name of the payer and display their values in the orders#new page. But what for, just to display, because the values will not be submitted with the form in OrdersController#create and will be lost when saving the order. Any tips for that ?

Avatar

How can I pass an additions parameter through the clickable tble column link ?

Avatar

Hi Ryan, there is some problem with images no longer available in the ASCIIcast tab.

Avatar

Hi Ryan,

I followed this tutorial through but when i got to displaying users in my view, it worked for a bit and then it suddenly started throwing me this error:

undefined method `profile' for #Friendship:0x007fd8519f11f0

and im unsure where it came from. I applied friendly_id gem to my users after this point as far as my memory takes me so im not sure if that influences this in anyway. My models and controllers match to yours too so im sure that the code on that side isnt the problem.

Any ideas? Thanks
Nandu.

Avatar

Like the URL to this very page, I want to have urls like this:

http://domain.com/products/454-table-lamp

So I use friendly_id like so:

ruby
extend FriendlyId

friendly_id :slug_candidates, use: :history

def slug_candidates
  [
      [:id, :title]
  ]
end

Now, since friendly id generates the slug before the object is saved I end up with an url like so (Please note the missing id in the URL):

http://domain.com/products/table-lamp

Now while this is not too bad as such. As soon as I save another Product called "Table Lamp", I will get an URL like this:

http://domain.com/products/table-lamp-ebaf4bf5-a6fb-4824-9a07-bdda34f56973

So my question is, how can I make sure, friendly ID creates the slug containing the ID as well.

Avatar

It's like todomvc -- it's a goto app? Would you rather he do todomvc?

Avatar

Below is the code updated for Rails 4.2. Note: the Rails api says that the group_by method is deprecated in Rails, but don't be confused by that, they just mean that you use the Ruby group_by method instead of the Rails' modified version (which no longer exists).

tasks_controller.rb
def index
  @tasks = Task.order(:due_at)
  @task_months = @tasks.group_by { |t| t.due_at.beginning_of_month }
end
tasks/index.html.erb
<% @task_months.each do |month, tasks| %>
  <h2><%= month.strftime('%B') %></h2>
  <% tasks.each do |task| %>
    <div class="task">
      <strong><%= task.name %></strong>
      due on <%= task.due_at.to_date.to_s(:long) %>
    </div>
  <% end %>
<% end %>
Avatar

The clearness for your writing is simply decent and i could expect you're a specialist on this subject area. Well together with your authorization permit me to grab your feed to stay upgraded with up and coming post. You can take this munnar call taxi for any tours and travels program of your family. They are providing secured and comfortable cabs. http://www.munnarcalltaxi.com

Avatar

Could someone please explain me how to use Faye monitoring with Private pub, I would really appreciate it, thanks

Faye monitoring

Avatar

This works as is on Rails 4.2 except for the CSS. Combining other people's advice above the below works for me. Remove .pretty and add a. Change the url from the image folder to the assets folder.

th a.current {
  padding-right: 20px;
  background-repeat: no-repeat;
  background-position: right center;
}
th a.current.asc {
  background-image: url(/assets/up_arrow.gif);
}
th a.current.desc {
  background-image: url(/assets/down_arrow.gif);
}

You can also use Bootstrap 3 glyphicons instead of background images. Replace the helper method with this and leave out the css classes.

def sortable(column, title = nil)
  title ||= column.titleize
  if column != sort_column
    css_class = nil
  elsif sort_direction == "asc"
    css_class = "glyphicon glyphicon-triangle-top"
  else
    css_class = "glyphicon glyphicon-triangle-bottom"
  end
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  link_to "#{title} <span class='#{css_class}'></span>".html_safe, {:sort => column, :direction => direction}
end
Avatar

@Denis
Thanks for the Rails 4 updated syntax!!
Really helped me out.

Avatar

I am impressed with the way you covers the whole article. Thanks for sharing and keep posting such nice information. I am truly pleased to read this website which defines our thoughts. looking more from you in future. I think you did an outstanding job ! Thanks for this!

Avatar

Hey I was trying to invoke the message change for all pages so when i tried to use "/" i.e. root_path as a channel in broadcast method it didnt work but if i use any other link it works fine can some1 explain this ?

Avatar

How to fix this error "Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit)"

I have configured timeout as 20 but still I get same error.

Avatar

How to fix this error "Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit)"

Avatar

For any beginner like me, I would like to say that multiple fields and all_by dynamic finders have been removed. However single field ones are still usable.
For example:
  find_by_email will work
  find_all_by_gender will not work
  find_last_by_status will not work

Avatar

A quick reminder about older versions of Redis' default security settings... be sure to secure your Redis server from outside access. (bind to localhost and set up AUTH as default installs were accessible from the outside).

See: http://redis.io/topics/security and http://antirez.com/news/96

Avatar

Hey, can anyone please tell me how to start workling server. I tried script/workling_starling_client start command but it keeps saying
-bash: script/workling_starling_client: No such file or directory

I am a newbie to ROR and working on Ubuntu.

Avatar

hi
thanks for this awesome post
i use carrierwave for uploading and i have problem to upload image and video in one uploader
i can do that separately, but when i use include CarrierWave::Video & include CarrierWave::RMagick in my uploader, video not upload and i recive this error "Failed to manipulate with rmagick, maybe it is not an image?
any idea?

Avatar

I got stuck on the params.require/permit (Rails 4.2.4).

Note: my models have different fields than in the video example, but the nested permit structure for attributes should help you out. Notice how the answers_attributes is located inside the questions_attributes .

This is what wound up working for me

ruby
def survey_params
      params.require(:survey).permit(:name, questions_attributes: [:id, :content, :number, :_destroy, answers_attributes: [:id, :answertext, :score, :_destroy]])
    end
Avatar

I get this error "undefined method `table' for #Prawn::Document:0x007fb57e0551a0". Anyone knows what might be going on?

Avatar

to avoid the readonly error, use "reset_counters" instead of "update_attribute":

ruby
Project.reset_column_information
Project.all.find_each do |p|
  Project.reset_counters p.id, :tasks
end
Avatar

You can use this gem too

if you simply need to export data as admin to excel you can use this gem https://github.com/igorkasyanchuk/rails_db to excel or csv

Avatar

Hey there @jamlevi, I recently wrote up an article about this based on your question at:

http://ducktypelabs.com/how-to-use-has_many-through-with-additional-attributes-on-the-join-table/

You're on the right path with fields_for and accepts_nested_attributes_for.

I did also include an example repo on GitHub for reference and to play around with. If the use case in the article doesn't match what you're looking for, be sure to let me know in the comments section and I'll try to help out, cheers!

Sid

Avatar

If you need to upgrade your Rails apps to 4.2.4, you need to know how to use the activeresource gem that is now outside the Rails framework. In https://rubyplus.com/articles/2691 ActiveResource Basics using Rails 4.2.4 article, I cover the basics of getting a simple book application to talk to an inventory application using activeresource gem.

Avatar

How can we extends this solution to query ActiveRecord? Trying to keep the solution DRY.

So I would like to be able to use that logic to List(index) a resource and passing the Authorization parameters to ActiveRecord which would return only the authorized resources.

Cheers,

Avatar

Can Anyone help.
I am having an issue to use this in rails 4 app.

Avatar

Did you find any solution on this issue? I am using 4.2.1 and have same error. I am using angularjs-rails gem but no luck.

Avatar

In your ascii cast I believe there is a typo

jQuery ->;
$('#faqs').sortable();

should be

jQuery ->
$('#faqs').sortable();

There is an extra semicolon that was breaking my code.

Avatar

Late to the party here, but I co-wrote a few thousands words about our experiences removing un-used CSS and taking our Rails app CSS codebase down from over 3000 lines to under 1000 lines.

We did things quite lo-fi, with lowly grep and meticulous workflow that involved comparing development app screens (that were in our rewritten CSS) with production app screens (written in the old CSS) and ensuring everything looked the way we wanted it.

https://www.oxbridgenotes.com/articles/css_refactoring_from_append_only_to_modular_css

Avatar

Bobby, Daniel, did you ever figure out a solution to this? I can't get around this on the mobile web myself. If I upload more than one image file, only one of the images is uploaded multiple times.

Avatar

@Boa Ho Man Did you ever figure out a solution to this? I can't get around this on the mobile web myself. If I upload more than one image file, only one of the images is uploaded multiple times.

Avatar

Hi there,

Trying to get a spinner on the submit button rather than just disabling it. Usually I just do it with:

<%= button_tag "Submit", class: 'mb-xs mt-xs mr-xs btn btn-primary btn-block', data: {disable_with: " Wait..."} %>

But this doesnt seem to work. Any ideas?

Thanks

Avatar

hi folks, I am getting an: "uninitialized constant QuoteController::Prawn" error.

at the following line (with the code in the relevant controller):

                    format.pdf do
---> here --->  pdf = Prawn::Document.new

anybody have any ideas? It's giving me grief!

Avatar

Code is upgraded to Rails 4.2.4 and latest draper version : https://github.com/bparanj/draper

Avatar

in Rails 4.2 this code gives me error
undefined method `reject' for nil:NilClass

product.update_attributes!(params[:product_params].reject { |k,v| v.blank? })

Avatar

Are you referring to the commercial NGINX Plus offering? The open source NGINX is always free as in free beer

Avatar

Looks like NGINX is no longer free. Anyone know of any other options?

Avatar

How I can do this for Active Admin??

Avatar

This also works:

self.category = Category.find_or_create_by(name: name) if name.present?

Avatar

Is this still relevant and working in the latest Rails?

After trying to make it work in my project for hours, I downloaded the source as a new project, ran db:setup and seed, and it doesn't work either (won't even load index without throwing a Nilclass error)

Avatar

ActionController::Metal is basically a stripped down rendition of ActionController::Base. It's chiefly utilized for API's on account of it does exclude modules that regularly accompany a Rails controller, in this way enhancing execution.

ref: http://laustan.com/

Avatar

For quick login into system:
https://github.com/igorkasyanchuk/any_login
Support Authlogic and other auth gems.
Please give it a try!

Avatar

Please check my gem https://github.com/igorkasyanchuk/any_login
It can really make your life easier with changing logged in user.
Your feedback is appreciated.
Video: https://www.youtube.com/watch?v=978DlHvufSY&feature=youtu.be
PS: this is my first solid gem :) and I hope you will like it.