Activity
Posted in Any good regex rules for validation?
Validating URLs is tough for the same reasons that validation on emails is tough. You can't verify the url or email is correct or live, only that it fits a format with regex.
It looks like Diego's regex here is the best option for correctness. https://mathiasbynens.be/demo/url-regex
Another great site for testing regex is http://rubular.com
It looks like on the Ransack docs, they do this:
class Artist
has_many :memberships
has_many :musicians, through: :memberships
end
artists = Artist.ransack(musicians_email_cont: 'bar')
Great post Andrew! That's a great approach and breakdown on the gotchas. You could either use a randomly generated ID of some sort, or you could add an incremental ID scoped to the company in as well. That can be nice so that you have more memorable ID numbers if you need them. This is how Github pull requests always start with #1. The real database ID is a separate number.
I'll be recording a couple episodes soon on how to set up multitenancy with subdomains. It's definitely not a simple thing, but really isn't too bad once you break it all down.
Posted in Setup MacOS 10.10 Yosemite Discussion
Oops, fixing!
Posted in Forum Series Part 2: Routes Discussion
Yeah the rollbacks only really happen when validations have failed to pass. That's something you'll pick up along the way and it helps point out what's wrong.
Best tip for debugging something like this is to make sure you've got the "byebug" gem installed and stick "byebug" into the controller before the save and then run the save manually from inside the byebug prompt. You'll get immediate output there letting you know if it worked or not and that can help save hours of debugging. :)
Posted in Forum Series Part 2: Routes Discussion
Looks like it's working correctly to me but validations caused it not to save. Double check all of those are passing.
Posted in Forum Series Part 2: Routes Discussion
You're really close. To create a form for a new comment on a recipe, you would do "form_for([@recipe, @comment])"
To create a new like on a recipe comment, you would do "<%= form_for([@recipe, @comment, @like]) do |f| %>"
I usually go for simplicity and don't use decorators for something like this. It's just a single method and I've already got a helper available so putting it there makes sense to me.
I find decorators are great for more complex things that manipulate record data into something more visible. A contrived example is a UserDecorator that has a "name" attribute that combines the "first_name" and "last_name" fields and does similar things for addresses. That rarely belongs in a model but it's a bit more logic than you'd want in a bunch of separate helper methods.
Ah! Thanks. You find my copy-paste job from last version. ;)
Posted in Best way to render a page as a PDF
Unfortunately PDFs are a pretty tricky thing. I've been using Prawn, but it's annoying to use.
I haven't used it, but I think wicked_pdf is probably the way to go.
Posted in Exporting Records To CSV Discussion
I believe that ActiveRecord::Relation remembers which model class it originated from, so when you call "to_csv" on a Relation it knows to delegate it to the User class. This is how scopes work too. It functions in pretty much the exact same way.
Yes, published_at is a column and published? Is just a method delegating to published_at? so it's more readable.
It's basically gonna be like this I think with a regular select tag.
<%= f.select :location_id, @locations.map{ |c| [c.title, c.id, data: {icon: c.icon, description: c.description}] %>
This is pretty simple actually. Just did it on One Month's app. You'll add data attributes to the options in the select, and then you can grab those on change to display on the side. This is using simple_form, but you can convert this to a regular select_tag.
<%= f.input :location_id, as: :select, collection: @locations.map{ |c| [c.title, c.id, data: {icon: c.icon, description: c.description}] } %>
Elsewhere you would have an empty div for the location details:
<div class="location-details"></div>
jQuery ->
$("#location_id").on "change", (e) ->
selected = $("#location_id option:selected")
$(".location-details").html("""
<img src=#{selected.data("icon")} />
<h3>#{selected.text()}</h3>
<p>#{selected.data("description")}</p>
""")
Of course, if you have an item pre-selected, you can have the JS fire the function on page load as well to use the selected data.
Posted in Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion
Yep, I believe so. Python makes it always explicit, but it can be a little confusing in Ruby since it isn't required to access but it is require to set attributes.
I can but it might take a while. In the meantime, you can check out their backend section. It pretty much walks you through it all. Just need to know your Key and bucket name from AWS. Just create your S3 bucket first and fill in the rest.
You can apply scopes to ransack search results to also include it in the query. @q.result.my_scope
You're right that you should get body in the controller in params. In the controller you should get params[:q][:subject_cont] with Ransack.
Posted in Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion
Yeah they are. Check out the Mandrill episode to see how I set that up. https://gorails.com/episode...
Posted in Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion
The only real time you need to use "self" in the model methods is when you want to assign an attribute. Not using self will create local variables. If you're just working with the values and not changing them, you don't have to use "self".