Sascha M.

Joined

1,210 Experience
1 Lesson Completed
0 Questions Solved

Activity

Posted in Change Layout based on current URL

Hi all,

let's say I wand to build a whitelabel product.

I want to display different layouts (Logos, CSS, ...) based on the current URL the website was accessed by.

E.G.
a123.mywebsite.com should render a different layout than
b124.mywebsite.com

I couldn't find anything describing something like that anywhere :(

Thanks in advance!

Posted in Streaming CSV Output to the User's Browser

Hi there,

unfortunately this is still relevant for me :(

Anyone who knows the solution?

THanks,
Sascha

Posted in [HATCH] Some questions :)

Hey there,

i have a few questions rg. your new product Hatch.

  1. is there a Heroku-like way to insert a SSL cert or do we need to do that manually?
  2. What permissions are we granting so you can manage the server?
  3. How are you storing ENV variables (encrypted?)?
  4. What about migrating later from DO to another provider that you will add in the future? Is it a "one-click" migration from one server to another?

Heroku just announced automated certificate management with Let's Encrypt. Maybe thats something to consider aswell: https://blog.heroku.com/announcing-automated-certificate-management

Thanks,
Sascha

Posted in Background Jobs

thx will take a look :)

Posted in Background Jobs

Hey there,

I'm using nested attributes to generate a bunch of records at once. I'm coding a tool that crawls IP and Website Informations.

The nested attributes are set up like this:

-Company
--has_many: IP-Areas
---has_many: IP-Subnets
----has_many: IP-Addresses
-----has_many: Sites
------has_many: Targets

Each one belongs_to the respective parent. But when it comes to IP-Addresses we're speaking of 1.000.000+ records. You only need to enter the Company name and everything works like a charm. IP-Areas is receiving a ID which identifies a lot of subnets, the subnets are getting iterated over and then I have the IP-Addresses. From there I'm generating a bunch of other records.

So my question:

The form in which you type in the company (and that basically triggers EVERYTHING else, which is pretty cool) takes ages to load because there is so much processing in the background.

I can't find a good tutorial how to actually move everything inside a background job. I'm really stuck there. Do you know a good approach on that or a good ressource that I can look up (not the RoR officials please..).

Thanks a lot,
Sascha

Posted in Multistep Signup-Form

Hi there,

do you know a elegant and quick way to create a signup page like cloud9 have?

https://c9.io/signup

Thanks a lot in advance!

Posted in Streaming CSV Output to the User's Browser

Hello,

I'm referring to https://gorails.com/episodes/export-to-csv?autoplay=1

is there an easy way to add a function to actually stream the file contents to the User's Browser, like described here: https://medium.com/table-xi/stream-csv-files-in-rails-because-you-can-46c212159ab7#.v64gu8o6r instead of having the file generated on the server.

How would you adjust the code of the "Export to CSV" episode to achieve that?

Thanks a lot,
Sascha

Posted in Multiple select for CSV Export

Perfect. Thank you for the hint. I've resolved it like this:

Form:

<%= f.select :brand, Brand.all.collect {|x| [x.company, x.company]}, {}, :multiple => true, :size => 8 %>

Controller:

params.require(:report).permit(:title, :start, :end, brand: [])

Model (to remove characters):

    before_save do
    self.brand.gsub!(/[\[\]\"]/, "") if attribute_present?("brand")
    self.brand.gsub!(/\A,|,\Z/, '') if attribute_present?("brand")
    self.brand.gsub!(/, /, ',') if attribute_present?("brand")
    self.brand.strip! if attribute_present?("brand")
    end

then

        brands = self.brand
        brands = brands.split(',')

to turn it into an array.

then loop through it, with:

brands.each do |b| ...

Posted in Multiple select for CSV Export

no one? :(

Posted in Multiple select for CSV Export

Hi there,

My users can create a report record which is basically a scaffolded model "Report" with controller and views. The users can use this model to create records that a CSV method is using to query 2 other models: Order (parent) model and the corresponding Sale (child).

The Report model contains these columns:

t.datetime "start" *(for createdat between (?) and (?))*
t.datetime "end" *(for createdat between (?) and (?))*
t.string   "brand" *(brand = ?)*
t.string   "team" *(team = ?)*

Short excerpt of the CSV query looks like that:

Order.where("created_at between (?) and (?) and brand = ? and team = ?", self.start, self.end, self.brand, self.team).each do |order| order.sales.each do |sale|

This basically outputs each single Sale record in one line. So when 1 Order contains 5 sales, then 5 rows are printed into the CSV file.
That works perfectly with a single brand and a single team.

Now I want to do offer my users multiple select of brands and teams. E.g. when the brand is "Adidas" and "Nike" and the corresponding teams are "US" and "Europe" I want to put both outputs into one CSV instead having the user to create 2 reports.

I'm really struggling with that. What do I need to adjust so that multiple values are getting saved into one record, like brand = "Adidas, Nike" and team = "US, Europe" and then have this array parsed and get that into the CSV AR Query.

Thanks a LOT in advance,
Sascha

Posted in Multi select form & DB search

Hi there,

I want to allow a user to select multiple brands and teams in a select form field. I am using the user's input to create CSV through running a query.

So far I only can query single teams and brands:

 ...
Order.where("created_at between (?) and (?) and brand = ? and team = ?", self.start, self.end, self.brand, self.team).each do |order|
 ...

Do you know how to solve this?

Posted in If-clause not working

I've created a little tool which pulls a price from another table according to what was sold. This works perfectly fine.
However I need to include a discount logic into that. There should be 3 ways to give a discount:

  1. Enter discount manually (type in the value)
  2. Waive 1, 2 or 3 times the monthly price
  3. Discount up to 25% of the monthly price

All of the above can also waive the one-time Setup Fee (SuF).

Unfortunately the discount logic does not work and I can't find the reason why. Everything (price, setup fee etc.) gets added correctly to the record but not the discount. Also the values for discountquantity, discount_percentage, waive_suf are getting saved to the record as well. So the conditions to enter the respective if-clauses should be there.. What am I missing here? My guess is that I'm not returning the value correctly back to save it. I get no errors. The value for discount just does not get saved to the db.

Please find the explenations in the code below:

sale.rb

class Sale < ActiveRecord::Base
      ...
      before_save :discount
      ...

      def discount=(discount)

        #checks if manually typed discount is present and the discount value is not greater than the value defined in the user model (maxdiscount)
        if discount.present? && current_user.maxdiscount >= discount.to_d
          discount.to_s.gsub(",", ".") #need to transform comma into point
          discount = discount.to_d * quantity
          discount
        end

        #checks if discountquantity (1,2,3 months for free) is present
        if discountquantity.present? #discountquantity is the value (1,2,3) months for free
          discount = discountquantity * price
          discount
        end

        #checks if discount is 10%
        if discount_percentage == 10 #discount_percentage can be selected from the user in a dropdown
          discount = price * quantity * 0.90
          discount
        end

        #checks if discount is 25%
        if discount_percentage == 25
          discount = price * quantity * 0.75
          discount
        end

        #checks if SuF should be waived
        if waive_suf == true #can be selected from the user

            #if available the Setup fee gets pulled from another table
          if Warehouse.where(:product => self.product).where(:brand => self.order.brand).pluck(:suf).present? 
            suf = Warehouse.where(:product => self.product).where(:brand => self.order.brand).pluck(:suf).sum
            suf = suf.to_d * quantity
            suf
          end

          if setup.present? #can be entered manually
            setup = setup.gsub(",", ".")
            setup = setup.to_d * quantity
            setup
          end

          setup_fee = suf + setup #sums that up

        end

        self[:discount] = discount + setup_fee

      end #def discount=(discount)

    end

Sales Schema (simplified)

t.integer  "quantity",            default: 1
t.text     "comment"
t.decimal  "discount"
t.decimal  "price"
t.decimal  "setup"
t.integer  "discountquantity"
t.boolean  "waive_suf",           default: false
t.integer  "discount_percentage"

Many many thanks in advance!

Posted in Limit CSV export by Day, Week and Month

Hi there,

is there an easy way to limit the results inside a CSV export to a specific time-frame, like day, week and month?

Thanks!

Posted in Rails console hacks :)

Hi,

I got it somehow.. Order.all.each do |tname| tname.team = User.where(:id => tname.user_id).pluck(:team).shift end

If I type this into the console the records get filled but not saved. What should I have to add to save the records?

Order.all.each do |tname| tname.team = User.where(:id => tname.user_id).pluck(:team).shift self.update_columns(team: tname.team) end or Order.all.each do |tname| tname.team = User.where(:id => tname.user_id).pluck(:team).shift self.update_attributes(team: tname.team) end are both not working.

>> NoMethodError: undefined method `update_attributes' for main:Object

Any ideas?

Posted in Rails console hacks :)

Hi there,

I need some help how to handle the rails console commands. I'm really stuck here..

I've recently added a new column (teams) to my Sales and Orders model. Both models containing the user_id from the User model.
The column team already exists in the User model. So I want to do this:

Fill the team names in the Sales and Orders model through the user_id from the User model and pull the team name from there.

Something like (pseudo sql): insert team into Sale.team from User where user_id == Sale.user_id

I hope you get what I mean :)

Posted in How to use the Sentimental gem

Just FYI:

I did the redundancy check like this:

client.search(query).each do |tweet|
 find_or_create_by(body: tweet.text, tweet_id: tweet.id)
end

Posted in How to use the Sentimental gem

Ok, got it. Is there an easy way to do the following:

Let's say I want to get the sentiment of Game tweets and I have a Game model in which are many Games entered, e.g. Hitman.

Is it possible to look up the Tweets as soon someone views the page and handover the title "Hitman" to the search query automatically? Also: How can I make sure that Tweets are not getting added twice .first_or_initialize? Thanks in advance!

Posted in How to use the Sentimental gem

Really really good episode! This is EXACTLY what I needed :P

How would you automate the app, so that you have a search field inside your rails views so that you don't have to go into the console each time?

Posted in How to use the Sentimental gem

Hi Chris,

how awesome is that?! I'm very excited! Actually I'm interested in both the postive/negative and percentage scores.

Cheers,
Sascha

Posted in How to use the Sentimental gem

Hi there,

I want to use the Sentimental gem to automatically check if an article is positive negative or neutral. This gem here: https://github.com/7compass/sentimental works fine in the Rails console. But I really have no clue how to use it in my scaffolded articles model - or inside the views. Do you have any ideas?