Jacob Montgomery

Joined

33,740 Experience
33 Lessons Completed
40 Questions Solved

Activity

Posted in Allow lvh.me with my ISP router

Unfortunately for your situation you're going to have to work in a hacky way.

If you're on Windows, use Notepad++ to edit your host file. By using Notepad++, as long as you don't close the tab that the host file is being edited in then everytime you relaunch Notepad++, the host file tab will be opened. Then, just stack your subdomains:

192.168.1.5 lvh.me sub1.lvh.me sub2.lvh.me sub3.lvh.me

Not ideal, but it works.

Beyond this, you could try setting your routers DNS to use Google DNS - 8.8.8.8 and 8.8.4.4 - this may or may not work. You could also try updating your computers DNS to use Google as well. This should bypass your ISP's DNS... but no guarantees...

Ahh, that's an interesting distinction there.

After some Googling, I came across alias_attribute I haven't tried it, but from what I'm gathering it looks like it may solve your issue.

Check out: http://www.chrisrolle.com/en/blog/aliasing-the-rails-way

Posted in Allow lvh.me with my ISP router

Interesting...

Reading this: https://productforums.google.com/forum/#!topic/googlewifi/-hv_AGjhZnU

It looks like there some cases where your router could be stubborn with local addresses. Have you tried disconnecting your rails box from the network all together and then seeing if you can access lvh.me? That should work if it's related at all to your router.

If it does work, try updating the host file as mentioned in my previous post on your rails box the same way, just use 127.0.0.1 instead of the 192.168.1.5 address, and then ultimately the actual IP address if it still balks at localhost

Posted in Allow lvh.me with my ISP router

Are you getting the error from the same computer running your server, or are you trying to access it from another computer?

If trying to access from another computer on the same network, the easiest thing to do is update that computers host file to point to your rails computer's IP address. So let's say the IP address for your rails box is 192.168.1.5, on your other computer you'd update the host file to something like:

192.168.1.5 lvh.me

Check out this resource for how to update your host file depending on the OS you're on: https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

From there, you may need to open up port 3000 on your router. You'll have to log in to your router and setup the port 3000 to forward to your rails box IP address.

And just for clarity, 127.0.0.1 is a loopback address that only pertains to the current box you're on. Check out https://www.lifewire.com/network-computer-special-ip-address-818385 for more details. So if you're on another box trying to access your rails box, you wouldn't enter 127.0.0.1, you'd have to enter that box's IP address.

Hey Jay,

You should be able to use alias_method

alias_method 'CustomerName', 'name'

Check out: https://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html

Hah, great! Glad that worked - although you may still want to spend some time investigating where the collision is when you have more time. Technically you shouldn't need this fix as far as I can tell, so this could be a sign of a bigger problem that may cause you some grief down the line.

And no sweat, that's what this community is here for! Just pay it forward and help someone down the line when they're in a bind! :)

Posted in Embed Youtube video in Rails app

@Zanger02, right where it says <%= @episode.youtube_id %> in

<iframe src='https://www.youtube.com/embed/<%= @episode.youtube_id %>?rel=0&autoplay=<%= params[:autoplay] || 0 %>' frameborder='0' allowfullscreen></iframe>

Which would render something like:

<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/lQOLrycmXC4?enablejsapi=1&amp;autoplay=1" frameborder="0" allowfullscreen=""></iframe>

This assumes you're passing an @episode object that has an attribute named youtube_id - your specific app may vary.

Hmm, looking at this: https://github.com/uxsolutions/bootstrap-datepicker/issues/50#issuecomment-90855951

Try updating your JS to this:

$(document).on('turbolinks:load', function() {
  $('#patient_date_of_birth_modal').datepicker({
    format: 'yyyy-mm-dd'
  }).on('hide', function(event) {
    event.preventDefault();
    event.stopPropagation();
  });
});

Hey James,

Which version of the datepicker are you running, and which one?

If you check out this pen: https://codepen.io/nanosplit/pen/wPWZvr you'll see BS4 + this datepicker does work in the vanilla BS4 modal as you'd expect.

Hey Luca,

Yes, I used Chris' Simple Calendar to handle the calendar.

In the image below, the user is first presented with all the dates of the month. When a user selects a day, it does an AJAX request to determine what the available slots are for that day, then presents them with the available dates.

Once a user selects a timeslot, the rest of the form appears and they can fill out their info. In order to deter race conditions, when a user selects a timeslot, it is saved to a HoldTime table which will make that slot appear unavailable to anyone else who visits within X amount of time (I forget the limit I set, maybe 3-5 mins)

Hey Pranay,

I recently implemented the setup linked below and its been really nice to work with. Be sure to check out the completed repo to see it all tied together.

https://medium.com/@nicolasblanco/developing-a-wizard-or-multi-steps-forms-in-rails-d2f3b7c692ce

Posted in Having trouble figuring out net/http and API calls.

Hmm, well I don't see anything that jumps out that would be wrong with your setup, but I've never really used the Net::HTTP API so I'm not much help there.

Have you by chance tried using one of the rest gems just to make sure it's not a setup issue? When I need REST support I drop in https://github.com/rest-client/rest-client and go to town.

I forgot these existed... have you tried using merge / or to retain the ActiveRecord::Relation instead of returning an array?

def all_tenders
  self.tenders.merge(self.tenders_by_group).uniq
end

I think or would be like this in your case if you're using AR 5+:

def all_tenders
  self.tenders.or(self.tenders_by_group)
end

See https://stackoverflow.com/a/9540911

Ohhhh ok, now I see what you're after.

That's a really good question, hopefully one of the more senior devs around here will chime in. I've done very similar methods like your all_tenders method which have worked fine for the uses I've had so I just left them as-is, but as you alluded to, it could probably be made more efficient with a single SQL query.

If you happen to find a good answer elsewhere, please post the results here too. I'd like to see what's the correct way to merge these two.

Should I seperate these out into individual scopes live I have started to?

I think it really just depends on how your application is going to use them. If there's ever a time that you'll need them independently of each other, then I would go ahead and make them their own scopes and just chain them. I generally try to keep my scopes / methods as simple as I can for the task.

Also how would I go about writing the scope to find the tenders assigned to the contractor

If I'm reading your associations correct, since you have has_many :tenders, through: :tender_contractors wouldn't it just be ContractorDetail.find(contractor).tenders ? Outside of that, each of your groups would have their own similar queries to show all tenders that are associated with that particular group.

Posted in Having trouble figuring out net/http and API calls.

I know it seems simple... but have you verified that you actually have put priviledges from the provider?

I'm dealing with this right now on a project where I have access to everything except for one resource, so I'm in a holding pattern until they fix the account. The error message returned was just null so I burned a day thinking there was something wrong with the connection method / query. =(

Hey James,

Have you checked out Chris' series on multitenancy?

https://gorails.com/series/multitenancy-crash-course

Try this:

subject = Subject.find(5)
subject.create_page(name: 'First Page', permalink: 'first', position: 1)

See: http://guides.rubyonrails.org/association_basics.html#has-one-association-reference

Posted in Layout for Devise with scoped route

Doh, well sometimes that's how it goes until we have more time!

Something I forgot to mention in my original post was that the registrations_controller.rb doesn't need any layout specified, you just need to make sure to namespace the controller...

class Members::RegistrationsController < Devise::RegistrationsController

Posted in Layout for Devise with scoped route

Hey Nick,

I'm still a bit foggy on devise and the routes, so this may not be the best way, but I had to do a similar setup where each user type had their own layout for the various devise functions and this is what has been working for that project:

devise_for :members, controllers: { registrations: 'members/registrations'}, :path => '', :path_names => {:sign_in => 'member_login', :sign_up => 'member_signup'}

Then for the views, you'll have a structure similar to this:

  • views
    • members
    • registrations
      • edit
      • new

And your controllers like:

  • controllers
    • members
    • registrations_controller.rb

Would love for someone with more expertise to chime in if there's a better way!