Save 36% for Black Friday! Learn more

Simon Moro

Joined

1,020 Experience
2 Lessons Completed
1 Question Solved

Activity

Actually... it seems it is auo loading them into the test environment... So, consider this closed :)

Hi!

Is there a way to create a fixture for a model that is not in the database? I built my app a few years back following a guide in which the Plans were loaded from a YML file and instantiated as ActiveRecord models, but not persisted in the database.

When I attempt to create the fixtures for Plans, I get:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "plans" does not exist

Because, of course, there IS no table for plans.

However, I still need the Plan model available in my tests.

Thanks in advance!

Here the app code - which works... Just need to create fixtures :)


plan_loader.rb - initializer

file_path = "config/plans.yml"
if File.exist?(file_path)
PLANS = YAML.load(File.read(file_path)).with_indifferent_access
end


plan.rb - model

class Plan
def self.plans
@plans ||= PLANS.keys.map { |k| PLANS[k] }
end

def self.all
plans.map { |plan| OpenStruct.new(plan) }
end

def self.where(args)
conditions = args.map do |arg_key, arg_val|
proc { |plan| plan[arg_key] == arg_val }
end
local_plans = plans.select { |plan| conditions.all? { |c| c.call(plan) } }
local_plans.flatten.map { |plan| OpenStruct.new(plan) }
end

def self.find(stripe_id)
plan = plans.find { |p| p[:stripe_id] == stripe_id }
OpenStruct.new(plan)
end
end

Posted in How to get started?

Hey!

I'm unsure which videos on here would be a good place to start, but if you're new to Rails, I think learning the fundamentals of its magic would be valuable. Have you been programming in Ruby for a while? Or other languages?

When I first learned Rails, I lacked an understanding of what was Ruby, and what was Rails... Learning pure Ruby, was a game-changer for me... Then I learned about how Rails works... Even simple things like the controller action will automatically render a view with the same name unless otherwise specified...

Maybe Chris would be able to point you in the right direction to some 'build simple a app' videos... Then come back here for the complex, cool stuff!?

Posted in Incorrect Content-Type Response Headers

Hey!

What's the context? I found with one of my apps, mp3 files were being uploaded to the server with different content-types... It turned out the OS and the browser was affecting them... On one computer it may upload as 'audio/mp3' on another the exact same file uploaded as 'audio/mpeg3'...

Is this being set on upload?

Hi there!

I'd love to know if there's a straightforward way of implementing S3 accelerated uploads for certain users, with ActiveStorage. Essentially, I want my paid users to experience faster uploads.

I can see turning it on globally is easy in config: use_accelerate_endpoint: true

Any assistance in finding a way to set it dynamically would be greatly appreciated!

Thanks :)