Brent C

Joined

780 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Multitenancy with custom domain names

We have a multitenant application with custom subdomains using a wildcard SSL on Heroku. While this has been great for our clients they are now requesting the ability to add their own domain names.

Any suggestions on
1: How to handle routing of custom domains to client subdomains.
2: How to integrate this into Heroku dynamically.

Any notes or direction on implementation of this feature would be greatly appreciated!

Posted in Affiliate Program Gems

I have been looking into that one. But, I've been leaning towards rolling my own. From what I gather online, it's not to complicated just takes some mapping out depending on the complexity. A multi-tier program seems to get more complex but luckily I'm not needing that right now, haha.

It would be nice to have a comprehensive video tutorial to reference *hint, hint, wink, wink. LOL

Have a HAPPY NEW YEAR

Posted in Affiliate Program Gems

I would love a tutorial on creating an affiliate program... Anyone have any gems they can recommend?

Posted in Versioning question.

I have a website where I would like to offer users the ability to edit the public facing data. However, after the data is edited I need to place the model in que for review. If edits are acceptable then the new version will become public facing.

Is the Paper Trail gem the right approach for this?

Thanks.

Posted in Where to put my Big Ole' Array

Thanks James. I try to keep this in mind, almost like I have Sandy Metz looking over my shoulder. :P

However, I often find myself questioning when and where to abstract. How small is too small of an object, should I place this method in the model or is it better suited in the controller or.. do I make a new Class since it's "kind of" a service object. It's not so much when it's black and white but the grey area that I still struggle with.

I think like you said I should ask myself more often if I can separate the concerns and/or responsibilities. -Thanks

Posted in Where to put my Big Ole' Array

Thank you. I knew it didn't feel right in either or mixed between the two. The new service class feels much better!

Posted in Where to put my Big Ole' Array

I have an array of states and abbreviations that I check when a user is performing a search. If the items is not in the array it moves on to using a geocoded service. I do the initial check currently in the controller and geocoding method is in the model.

My questions is where should I put this initial state check array? I feel like it bloats the controller or the model since it is many lines.

Thanks.

Posted in Must Read / Must Watch

It's so TRUE but it can be soooo hard to put stuff out there when you know it's far from "perfect"

Posted in Native Mobile Options

Ok, after further review the Phonegap option didn't work for my given application. That being said, I am looking into Rubymotion. However, first things first I want to learn more about building a Restful API using JSON API to interact with. Poking around now to find the best resources for this.

Some resources.
https://robots.thoughtbot.com/welcome-aboard-youre-riding-ios-on-rails
https://www.airpair.com/ruby-on-rails/posts/building-a-restful-api-in-a-rails-application

Posted in Native Mobile Options

Thanks Chris I'll check it out and report back.

Posted in Native Mobile Options

I was thinking about starting with the path of least resistance. Then releasing an improved native experience once I learned more on what the customers needs were. I have not fully developed any native mobile applications so my thought was that a Hybrid using Phonegap could provide me with the training wheels with a quicker release cycle. BUT... That being said, if the Phonegap experience is terrible I rather just put in the time to go fully native. I'm all ears if you have a suggested/recommended pipeline.

Posted in Native Mobile Options

I have a Rails 4 app that is fully responsive and works good on the mobile browser. However, I want to make native apps for it for iOS and Android.

What are some recommended steps? Is Phonegap a good option still? Are there any great resources/posts/tutorials/books on taking a rails app and making an API for mobile?

What are some next steps that people/solo devs follow?

Posted in Must Read / Must Watch

Sandi Metz - All the Little Things Rails Conf 2014
https://www.youtube.com/watch?v=8bZh5LMaSmE

Posted in Nested attributes with collection_select not saving

Thanks. Yeah, as you can see and as Chris mentioned it was a bugger of a bug. Hard to nail down what was causing the issue, just took some time.

Posted in Nested attributes with collection_select not saving

First thing was organization. In order to achieve my main goal, I had to rethink what I was trying to do first. Needing to create/update new RaceEvents(join Model) for each Race. However for each RaceEvent I needed to display all the options in a collection_select that was populated from EventTypes.

The short of it was to make the join model my nested model form and inside of that fields_for block, add the collection_select. I then needed to make sure those params were accepted so I had to edit my strong params to make reference of the event_type_id in side of the join models attributes. I will display the updated code below.

class Race < ActiveRecord::Base
  has_many :race_events, dependent: :destroy
  has_many :event_types, through: :race_events
  accepts_nested_attributes_for :race_events, allow_destroy: true
end

class EventType < ActiveRecord::Base
  has_many :race_events
  has_many :races, through: :race_events
  accepts_nested_attributes_for :race_events
end

class RaceEvent < ActiveRecord::Base
  belongs_to :race
  belongs_to :event_type    
end

Now for the Strong Params. Notice how in the join model attributes (race_events_attributes) I needed to include :event_type_id. This through me for awhile. It’s needed to make the proper association, seems almost obvious now. But a couple days ago it definitely wasn’t. :P

def race_params
    params.require(:race).permit(:name, :description, race_events_attributes: [:id, :price, :summary, :event_type_id, :_destroy] )
  end
end

Finally the view. A couple of gotchas here too. On the collection_select it’s not necessary and important not to include the object directly. This seems to cause a bit of confusion (as this is most of the people problems regarding Collection_select on SO)

<%= form_for @race do |f| %>
   <%= f.fields_for :race_events do |event| %>
    <div>
      <%= event.collection_select :event_type_id, EventType.all, :id, :name %>
      <%= event.text_area :summary %>
      <%= event.text_field :price %>
      <%= event.check_box :_destroy %>
      <%= event.label :_destroy, “remove event” %>
    </div>
  <% end %>
<% end %>

At the end of the day, it wasn’t one problem it was an assortment that needed rethinking and refactoring to get working properly.

Hope that clears it up a little for anyone in need. And thanks GoRails team and community for support!

Posted in Nested attributes with collection_select not saving

I got it!

Since I was dealing with a has_many through relationship I needed to reorder a few things. I will post it up shortly.

:)

Posted in Nested attributes with collection_select not saving

Started PATCH "/assistants/134-gilbert-event" for ::1 at 2015-03-19 13:36:57 -0700
Processing by AssistantsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"nsJc3ywZCW9hhk7fyY3jZeuwEhTpOQ4IwOxVYUoLRuMplW7bkCnHZgrt024RL0NVa8v6doFaJPjVPcwTc2Hxg==", "race"=>{"name"=>"Gilbert Event", "race_date"=>"2014-11-22", "city"=>"Gilbert", "state"=>"Alabama", "address"=>"", "zipcode"=>"", "country"=>"Australia", "email"=>"[email protected]", "phone"=>"", "links_attributes"=>{"0"=>{"website"=>"http://gilbertevent.org", "registration"=>"", "other"=>"", "id"=>"32"}}, "start_time(1i)"=>"2000", "start_time(2i)"=>"1", "start_time(3i)"=>"1", "start_time(4i)"=>"00", "start_time(5i)"=>"00", "price"=>"", "event_types_attributes"=>{"0"=>{"id"=>"2"}, "1"=>{"id"=>"3"}, "2"=>{"id"=>"5"}, "3"=>{"id"=>"6"}}, "headline"=>"", "description"=>""}, "va"=>"employee_11", "commit"=>"Add Race", "id"=>"134-gilbert-event"}

Posted in Nested attributes with collection_select not saving

Saving the records. Form renders perfectly.

Posted in Nested attributes with collection_select not saving

In my edit form I simply cannot figure out why collection_select isn’t saving the various values when it's nested. It works fine if I use a {multiple: true} and pull it outside of the fields_for event_types. Am I missing something? I have tried many configurations regarding strong params.. nothing.

Thanks for any assistance.


class Race < ActiveRecord::Base
    has_many :race_events, dependent: :destroy
    has_many :event_types, through: :race_events 
    accepts_nested_attributes_for :event_types
end

class EventType < ActiveRecord::Base
    belongs_to :discipline
      has_many :race_events
      has_many :races, through: :race_events
end

class RaceEvent < ActiveRecord::Base
      belongs_to :race
      belongs_to :event_type
end

class RacesController < ApplicationController

  def edit
    authorize! :add_details, @race
    if @race.links.empty?
      @race.links.new
    end
  end

  def update
    authorize! :add_details, @race
    if @race.update(race_params)
      redirect_to …
    else
      render :edit
    end
  end
end

private
  def race_params
    params.require(:race).permit(:name, :description,:event_type_ids => [], event_types_attributes: [:id, :name])
end

Edit View

<%= form_for(@race, ... ) do |f| %>
  <%= f.fields_for :event_types do |event|  %>  

    <%= event.collection_select(:id, EventType.all, :id, :name) %> # This displays the collections correctly but they don's save when updated.

  <% end %>
  ...
<% end %>

Posted in Introduction to Importing from CSV Discussion

Fantastic! thanks :)

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.