shakycode

Joined

5,400 Experience
2 Lessons Completed
3 Questions Solved

Activity

Alex,

I think you are safe using Error has a class/model name as it doesn't collide with stdlib in Ruby or Rails. In fact I have a similar model in one of my older apps and it never caused issues.

If it doesn't feel right, then maybe you can change it to something like ErrorMessage or something like that, but I don't see it being an issue although others may be able to chime in with better intel.

Posted in Multi tenant best strategy

If you exclude users from the tenant then the model becomes global and not part of the tenant. If what you are looking for is a redirect from your main app to the domain you could create a simple form_tag that takes an org name or subdomain and on submit redirects via the controller to the proper subdomain. Basecamp does similar but they don't use Apartment. But this ended up working for me and my project.

Posted in Rails API backend with Electron Frontend

Thanks Aniket. I just don't have enough exposure to electron to speak intelligibly about it yet. However I saw that Basecamp has an electron client for basecamp3 and they are an all rails/api backend so like you said, it's just a ton of javascript.

Definitely affordable (free) to build one and it's a requirement of this new project I'm working on. If you have any examples or tutorials (I've yet to find anything decent) feel free to share!

Cheers!
-James

Posted in Rails API backend with Electron Frontend

I'm working on a SaaS platform that will be heavily API driven with a React or Vue front end. But there's a requirement for a desktop app to give the customer something "tangible" to hold in their hands (marketing is pushing for this).

What are my options if any for making a desktop app that connects to a Rails API backend. I've been looking at Electron and I think it's doable, but was wondering if anyone has done anything like this before and could offer some tips in getting started. In the meantime I'm reading the electron docs and seeing what's possible. At the surface since it's all JS it looks like it's just a matter of heavy javascript front end work making tons of API calls but I could be wrong.

Any guidance for an Electron newb like me is greatly appreciated.

And yes, I know this is not the best idea trying to make a desktop client for a web framework backed app, but gotta pay the bills :)

@masud, thanks but I'm already familiar with AR and DB optimization. I was wondering what your caching issue was that you made mention of.

@masud I think I may have misunderstood I thought you were talking about optimizing your cache, not dealing with N+1 queries. Either way, eager loading is the way to go. Thanks for posting this up.

Yeah there's no double yield, but in your conditional instead of just calling current_user you may want to use the helper method user_signed_in? to verify they are logged in.

One way you can DRY this up a little is to set the following methods in your application_controller

def vendor?
  user_signed_in? && current_user.has_role? :vendor
end

def user?
  user_signed_in? && current_user.has_role? :vendor
end

helper_method :vendor? , :user?

Then in your application,html.erb you can just call if vendor? or if user? to clean things up a bit. An these helper methods are available all across your application

@masud I'm not seeing the same caching thing that you did. What did you change to fix your issue so that others know. I think my issue is a leaky ActionCable implementation from rails 5.0.0.1

@naveen. Can you supply a sample repo on github for one of us to look at this issue? Or maybe some of your view and controller code? My guess is somewhere you're calling render twice on partials but I could be wrong or as Robert Paul said if you have a double yield somewhere that would cause it. But if you had a double yield in theory you'd see pages on top of pages if i'm not mistaken?

"If I'm a really great developer, I should be able to go from an idea to implementation without all these aggravations along the way."

Jacob hit the nail on the had but I had to chime in here. The aggravation never truly goes away. Imagine all the frustration you felt 6 months ago that you no longer feel because you've made great progress. Now you have leveled up and face a whole different set of frustrations.

As time goes on and you become more comfortable and confident as a developer you will still have frustrations and be potentially aggravated, but you'll have the tools and knowledge to help you mitigate "hitting the wall" much less.

Speaking for myself I've only been doing this for a little under 5 years and there's days where I just can't figure things out. 99% of the time it's me overanalyzing the problem and trying to break conventions instead of following them. Sometimes it helps to take a step back from the problem as Jacob suggested and come back to it another day/hour/etc. Taking a break is good for you and will help you recharge your batteries to come back and attack whatever it is that you were stuck on.

One thing that I cannot stress enough is learning Ruby. Rails is Ruby afterall so having a good handle on the language makes understanding and consuming the framework that much easier. When I first started I was writing so much Rails and almost zero Ruby so it got to the point where I was good at Rails but had no clue how to do simple things in Ruby.

I was fortunate enough to have Chris to give me a wakeup call and he told me I really needed to work on my Ruby to progress. So that's what I did. I still wrote Rails stuff but I started doing pure Ruby exercises to gain competency. After about 6-9 months a strange thing happened. I had competency in Ruby but Rails became so much easier to wrap my head around. So I would highly advise you diving into Ruby and gaining a better comprehension of the language.

Besides crondose.com which is excellent, I'd suggest picking up the Pickaxe Ruby book (you can probably find it cheap online used). Also once you are comfortable with Ruby I'd definitely recommend a subscription to Ruby Tapas. Avdi Grimm is really an excellent Rubyist and definitely one to learn from. Once your chops are up to par then I'd implore you to explore other things like Rubykoans, katas, and hackerrank challenges.

One particular exercise that Chris and I went through was a game called Ruby Warrior (google search for the URL). It's a game which forces you to write enough Ruby to advance your character to the next level in the game. Not only is it challenging but it's a lot of fun.

Anyways, sorry for writing a book but I figured I'd chime in and validate what Jacob said plus give my perspective on things.

If you ever have any questions please feel free to ask on the slack channel or hit one of us up via DM. GoRails is a friendly place full of brilliant, hungry folks who want to help!

Cheers!

@masud How is your memory profile looking now that you've switched to DO? Also what version of Rails are you on? I'm on DO and Rails 5.0.0.1 and am experiencing memory bloat in a mulitenant app with actioncable. I've isolated this to cable so far by disabling it but was wondering if you're on a newer version of Rails where the memory leak has been patched. I'm on a 1GB DO box and I start swapping/paging at about 50 concurrenct AC websockets.

Just curious if you were seeing similar degredation.

Late to the party here, but I remember reading somewhere that there's an open issue with ActionCable consuming excessive memory and leaking. This was on 5.0.0.1 but I'm not sure if it's applicable to your situation. Just figured I'd chime in with what I heard around the campfire.

Posted in Multistep Signup-Form

You can also look at Fuelux Wizard for a multi-step form without having to track state in the controller. Wicked is good but if you just need a basic multi-step form FuelUX is great. Here's the link http://getfuelux.com/javascript.html#wizard

Posted in RSpec w/capybara vs Mini Test

My .02c

I don't TDD. I've tried it and find it too constraining. As far as testing I really don't focus on 100% test coverage in production apps. I tend to focus on unit, integration, and system testing on the important parts that could easily break. You could say that testing is not my favorite thing.

As far as frameworks I'm agnostic. I work with both Minitest and Rspec. Like Chris and the others have mentioned Rspec has a DSL that you have to learn which is good if you're just starting out with Ruby and don't feel very confident yet. Minitest is pure ruby so for myself I find it a bit more flexible for my workflow. But I'm stuck in a space where I have apps that use each one.

But if I could pick one framework and stick with it. Minitest.

Also do some searches on YouTube for minitest and Aaron Patterson. He's really good with it and has a lot of best practice lectures on it.

Posted in How do i print out validation error?

There are several ways to do this and I actually had this same problem where nested validations were not outputting. I stuck this in my controller where I wanted the object validation errors to be logged to the development.log

Rails.logger.info(@object.errors.inspect)

Of course replace @object with your respective instance variable.

Posted in What do you listen to while coding?

Great post and good topic:

For me it depends on what I'm doing.

Sprinting: Aggrotech, Hellektro, Industrial, Trance, EDM
Research and learning new patterns: Classical
Tackling challenging pieces of code or debugging/refactoring: Death/Black Metal

@alex On the execJS stuff can you post a stacktrace from your capistrano.log? I seem to remember running into this before.

Posted in How to make form fields to display placeholder text?

Hey Adrian,

Setting a placeholder for the form fields are relatively straight forward. Taking your example form code you can do this:

<%= form_for([@project, @new_task]) do |f| %>
    <%= f.text_field :title, placeholder: "Your placeholder text here" %>
    <%= f.submit %>
<% end %>

This should give you what you need, but if for some reason I'm not understanding the full scope of the problem please let me know and I'll help where I can.

Cheers,
-shakycode

Chris answered this well, but there's also another option of using the God gem to manage sidekiq which I believe is based off of bluepill. Either way will work, but systemd can handle this as Chris mentioned.

Posted in What are your goals for 2017?

This is an excellent thread. Thanks so much for creating this.

My goals in 2017

  • Become better at Ruby and Rails
  • Finally tackle the front end and learn Javascript
  • Get more involved in React
  • Build a new SaaS platform and launch it as a startup
  • Quit my dead end job
  • Build tons of side projects to expand my portfolio and potentially solve real world problems
  • Finish my meme generator which I've been procrastinating on
  • Make new friends in the GoRails community and lend a helping hand where I can
  • Always be coding
  • Always be learning
  • Do things that scare me
  • Lose weight (had to throw that in there) :-)
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.