Author: heridev

Hello Guys, In this post I'm going to start putting all about queries in rails, so if you find any interesting query let me know and I can put it here, so let's get right to it: Something that I found really useful to understand how the joins works is using this image: If you want to retrieve all the orders that contain more than 2 shipments (Using Spree models) [rails] # this is using inner joins buy default from rails Spree::Order.joins(:shipments).group("spree_shipments.order_id").having("count(spree_shipments.id) > 2") [/rails]

Actually it is pretty straightforward you just have to download and use ngrok(it's free): [program] https://ngrok.com/ [/program] In my case I'm using a rails application so I just need to: [shell] # run my server in localhost rails server # at this moment it is available in http://localhost:3000 by default # if you want...

After thinking a little bit I don't remember writing too much about javascript and I really like javascript !!!, well here it is the first post that I want you to share with you guys. Sometimes you need to get the absolute url from javascript for those cases you can find useful the following function: [javascript] window.Utils = { httpUrlFor: function(url_params) { var domain, port; domain = "http://" + window.location.hostname; port = window.location.port ? ":" + window.location.port : ""; return domain + port + url_params; } }; # or in coffee-script window.Utils = httpUrlFor: (url_params) -> domain = "http://#{window.location.hostname}" port = if window.location.port then ":#{window.location.port}" else "" "#{domain}#{port}#{url_params}" [/javascript]

First thing you have to do is log-in to your server using ssh and going to the discourse installation path: [shell] # login in to your ssh account ssh youraccount@yourip.com cd /var/discourse [/shell] If you need to see the rails logs and see what is doing discourse the commands bellow are what you're looking for: [shell] # connecting to the rails application ./launcher ssh app cd /var/www/discourse #starts all the logs in console tail -f log/*.log [/shell]

Here you have the simple step you may follow: Go to your website and create a new user account Go to console [shell] bundle exec rails console [/shell] How to activate your discourse account manually(from console) if you are not receiving the confirmation email: [shell] token = User.last.email_tokens.first EmailToken.confirm(token.token) [/shell] Setup your account as an admin...

Sometimes when you're playing with new code it is kind of difficult to find out where they are declared or maybe this method are declared using metaprogramming and they are not explicitly declared: In most of the cases you can just copy your method or function and search it in the repository using ack http://beyondgrep.com/ or silver searcher(ag) https://github.com/ggreer/the_silver_searcher but if you are not able to find the method you're looking for using some of this searcher tools you can use some gem for debugging for example debugger https://github.com/cldwalker/debugger or pry https://github.com/pry/pry.

In the past days I attended the http://gophergala.com/ event which it was a really good start in the Golang world, I learned some stuff about Golang, after to read this previous sentences you are going to say WTF is this post about ruby or Golang well I wanted to start writting about the Gophergala because the code that we are going create is created with the aim and purpose of cloning all the repositories from an account in this case the gophergala organization using ruby in a rake task, Why Am I doing this? just to put in only one place all these great resources (I will put in my account all of this repositories in one repository).

Well I'm using heroku.com for staging purposes for one of our Customer projects and I found really useful to clone from time to time the staging db especially when the bugs arise, if you want to do that I'm going to show how to do it using the command line tool or using a rake task you can use whichever you prefer: Before to start with running commands make sure you have the heroku toolbelt installed: https://github.com/heroku/toolbelt

How to apply a Spree coupon promotion within console: [ruby] # search the order in this case I'm using the last one o = Spree::Order.last # apply the coupon code you already create from the admin panel section o.coupon_code = 'order_discount' # apply the coupon code specified handler = Spree::PromotionHandler::Coupon.new(o).apply [/ruby] ...