Activity
Posted in Mobile App with Devise Facebook OmniAuth
That's definitely something I'm not super familiar with, but can guarantee that many people have done it. Take a look at these answers here and see if they help at all. http://stackoverflow.com/questions/9587012/oauth-flow-iphone-rails-facebook
I think you would hand back the Facebook OAuth token to the Rails app and you wouldn't necessarily need the token_authenticatable gem.
You're welcome! I'm glad I was able to help. :)
Yeah, for sure. Also, I meant that it's great to use grouped_options_for_select
with f.select
just not grouped_collection_select
. Same goes for options_for_select
with f.select
instead of collection_select
.
Kinda confusing.
Yeah, I tend to shy away from those combined select helpers. The normal select with a separate call to options_for_select
give syou a lot more flexibility. It's what it does behind the scenes anyways.
I don't think you can with that. You would need to create the grouped options separately and pass to a regular select.
You should be able to create the grouped options with this and then pass it into a normal <%= f.select %>
http://apidock.com/rails/v4.1.8/ActionView/Helpers/FormOptionsHelper/grouped_options_for_select
Awesome, glad you got it fixed. I'd love to see the solution as well. Sometimes it is hard to debug those issues.
Okay cool. Can you paste the log of the post request?
Are you specifically having trouble saving the records or is the form having trouble rendering?
Posted in Advanced routing setup
Yeah, the find will throw an exception. I think this will work instead because find_by
doesn't throw an exception when the record doesn't exist.
before_action :set_product
before_action :find_products_if_not_found, if: ->{ @product.blank? }
private
def set_product
@product = Product.friendly.find_by(id: params[:id])
end
def find_products_if_not_found
# @product gets set in the before_action
if @product.nil?
@parent = Technology.friendly.find_by(id: params[:id]) || Industry.friendly.find_by(id: params[:id])
# Since this could be nil, we need to redirect or render a 404 if not found
if @parent.present?
@products = @parent.products
# Render the index template if we found a parent for products
# Since we are in the before_action this should halt rendering of the show action
render action: :index
else
redirect_to root_path
end
end
end
You'll want to set up the strong_params method to point to the Pundit scope for the user. That can return the list of fields you want to allow them to edit since it will be different for different types of users.
Check out this section in their readme. https://github.com/elabs/pundit#strong-parameters
Posted in JSON for Rails delegated attributes?
I'm a big fan of just using jbuilder for this kind of stuff. It makes it rather easy to render out absolutely anything you want and is pretty much just like using the xml builder if you're familiar with that. No need to override to_json
or anything. I believe it's intended to do pretty much the same thing as ActiveModel::Serializer, but jbuilder makes it feel more like a view that you're creating. You'll have full access to any instance variables set in the view and should be able to do what you want.
You'll just do this in your controller:
respond_to do |format|
format.html
format.json
end
And then create the view file as ACTION_NAME.json.jbuilder
.
I personally store my configs in a Git repo, clone it on each machine, and symlink the configs.
Posted in Sending emails with Mandrill Discussion
It depends on their SMTP system, I've seen the same delays at times. They might be queuing or batching emails behind the scenes or any multitude of things between them and GMail could be slow. I'm not quite sure.
Posted in Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion
Just leave that part out. For example:
class NotifierPreview < ActionMailer::Preview
def welcome
Notifier.welcome(User.first)
end
end
Posted in Javascript frameworks videos?
Start a new thread to discuss those features? I like the idea of not just building features but also comparing it to how a production site uses them.
Yeah, it's the items in the row in order. I just used a Ruby trick to split the array of items into separate variables.
irb(main):001:0> a, b, c = ["a", "b", "c"]
=> ["a", "b", "c"]
irb(main):002:0> a
=> "a"
irb(main):003:0> b
=> "b"
irb(main):004:0> c
=> "c"
Posted in Javascript frameworks videos?
The main purpose is for making a website that has a lot of interaction where reloading the page would be intrusive. Look at Facebook and Twitter. If every action you took reloaded the page...it would be really hard to use them.
jQuery can get you pretty far, but it's going to be very disorganize because it isn't built for the same purpose. It's good for smaller things, but when you're building realtime chat like Facebook has, you're going to want something more robust like one of these frameworks.
In a lot of cases, you will be good just using jQuery, Turbolinks, and no full JS framework if you want just want your pages to render faster and to have some decent interactivity. Shopify went with this approach and they're doing really well with it.
Haha no worries! :) Feel free to ask questions on the forum too.
Posted in Sending emails with Mandrill Discussion
You can pass in the object into the mailer as an argument. Just set that to an instance variable and render it in your mailer view. If you're using Mandrill templates, you can pass the values over as merge variables instead.
Posted in Storing Constant Date in Rails
If you want them to be editable, then storing them in a model makes sense. You can easily add and update them.
Otherwise if you really want them to be true constants, you could set a constant in Ruby in a Rails initializer file like so:
# config/initializers/countries.rb
COUNTRIES = [
"United States",
"Canada",
#... etc
]
And then you could reference the COUNTRIES
variables in your code in other places.