Please read for an updated status on RailsCasts:
Learn more or hide this
GitHub User: dideler
You should be able to just include gem 'haml-rails' in your Gemfile now and have it work.
Looks like it. The original projects seem to be unmaintained; the last commits were made years ago.
Ignore my above comment, you can simply use @items.offset + 1 as your starting count :)
@items.offset + 1
One more thing!
If you're displaying the total number of records found like @items.size, then paginate will now show an incorrect count. That will show the count for records on current page.
To get the count of all records found by the query, you'll want to do @items.total_entries.
Also, if you are displaying record counts in your views, those counts will now reset on every page. Here's how to get the starting count of the current page, from which you can easily continue the count for the current records displayed.
In this example, the count is a cell in a table row.
- @items.each_with_index do |item, i|
%td= i + 1
((records.current_page - 1) * 30) + 1
- i = record_count_start(@items)
- @items.each do |item|
- i += 1
Note my use of current_page. Other useful stuff that will_paginate provides:
To get the number of records on the current page, you can use size.
If you are displaying search results, you can paginate like this.
@items = Item.search(params)
@items = Item.paginate(page: params[:page]).search(params)
Thanks! I am using Postgres and you were right, converting the arrays from message.to and message.from to strings or getting the first elements solves the issue.
I can't get past the step where you create a new record using the email contents.
puts message.body # or body.decoded, both work
# The above works, but the below fails.
I get the error type_cast': can't cast Mail::AddressContainer to string.
type_cast': can't cast Mail::AddressContainer to string
Full stack trace here.
I'm confused about a few things.
Will this work with Rails 4?
You specify require: false for the mailman gem because you don't want it loaded in Rails but as a separate process. Is this how mailman is meant to be used? No where on mailman's userguide does it mention this.
There is no script directory in Rails 4? Sure I can just create it, but I imagine there is a better place to put stuff like the mailman_server file?
I just want to point out that you should use true and false for any boolean fields that you have. As seen in the ASCIIcast:
form.select :discontinued, [["Yes", true], ["No", false]]
You may be tempted to use 1 and 0 since those are the values used in the database for a TINYINT, but Rails will not show the correct default option for the select menu if you use integers. So make sure you use booleans!
Also, you can use search_field_tag instead of text_field_tag. That will create a text field of type "search".
Also, that last part about adding more fields to the search came in very handy, thanks! I was able to add a dropdown list to filter results in addition to the search.
Is this prone to SQL injection? It looks like you're directly embedding strings into your SQL queries.
For anyone who's using Rails 4 and is wondering about projects_path, don't worry. I'm a Rails newbie, but in my experience, Rails adds what you need to your routes file (app/models/modelname.rb) automatically when you create the controller.
If it doesn't, I believe adding the following line does it:
resources :projects # Replace "projects" with your controller name
Also, if you're wondering why we use def self.search instead of def search, it's because we want a class method instead of an instance method. In other words, it allows us to do Project.search, we're calling the method from the class, not from an instance of the class.
That probably means you're missing the search method in your model.
I noticed this screencast is pretty old. As some have mentioned, there's a faster faker (ffaker) now.
When I search through repos on GitHub, I noticed a lot of people are using the ffaker gem in their specs/ directory.
I'm new to Rails, and I'm not familiar with the specs/ directory yet. Is the info in this screencast still a good way to populate your DB with random fake data?