TwistingTwists

TwistingTwists

Best Practices from LiveBeats App

This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code.

Found this usage of rescue/1

I’ve been meaning to handle Ecto errors myself. So this comes in handy for next time.

Most Liked

dorgan

dorgan

Protip: if you press Y while seeing a github file it replaces the url at the address bar with a permalink so you can copy that instead of scrolling and clicking copy permalink

13
Post #7
RudManusachi

RudManusachi

First of all, thank you for this initiative!

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/live_helpers.ex#L494

Never seen a for loop like this before.

I’d recommend to post a “permalink” to the line in the commit. That file was changed 7 hours ago. And looks like the link doesn’t point to the place you meant to.

10
Post #6
mcrumm

mcrumm

Phoenix Core Team

Check out the Phoenix.HTML docs for Link.link/2– You can override the default (:get) link method. You can also provide a data-confirm attribute to prompt the user before following the link. This is all ancient UX stuff that you get when you include phoenix_html.js. :slight_smile:

Almost certainly, but take a look at router.ex to be sure. You don’t want to put destructive actions behind a GET method (especially a public one) otherwise any request to the path will trigger the destructive action. Imagine a search engine spidering your delete links– it’s not ideal.

TwistingTwists

TwistingTwists

OneLiner For loop

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/live_helpers.ex#L494

Never seen a for loop like this before.

Practical render_slots

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/profile_live.ex#L22

Message passing other component from present one - JS.push

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/profile_live.ex#L25
“switch_profile” is in player_live.ex
https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/live/player_live.ex#L208

Pattern Matching - via two variables in function - elegant

matching if current user is same as profile user or any other case.

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats/accounts.ex#L93

TwistingTwists

TwistingTwists

Who is current user in liveview app ? (even during redirects) More than just :fetch_current_user plug

https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/controllers/redirect_controller.ex#L9

This has conn.assigns.current_user - without worrying that current_user might not exist.

above is possible because of plug :fetch_current_user here → https://github.com/fly-apps/live_beats/blob/master/lib/live_beats_web/controllers/redirect_controller.ex#L6

Where Next?

Popular in Guides/Tuts Top

slouchpie
Warmest greetings, comrades. I recently started using :dns_cluster (GitHub - phoenixframework/dns_cluster: Simple DNS clustering for dis...
New
hauks96
Hello everyone, I created a deployment tutorial for Phoenix applications with Kubernetes (microk8s) a few months back with the goal of s...
New
kuon
I have a page with a large state that is loaded from DB, let’s call that “data”. I have a root live view that load “data” on mount and r...
New
zachallaun
Hey friends, wanted to share a tiny shell script I’ve been using to start Livebook with easy access to either a running production server...
New
rhcarvalho
After collecting information from multiple sources (this forum, blogs, StackOverflow and GitHub), I was finally able to successfully embe...
New
dmitriid
This is not a question, but a post for anyone who may need it in the future. Sometimes some browsers may mangle the filename if it’s non-...
New
thetechnologyvault
One of our team members just published this getting started guide for Elixir/Phoenix devs to use the Nanobox platform: https://content.n...
New
Zurga
In a quest to optimize the amount of data sent between the server and client I recently decided to try to use MessagePack instead of JSON...
New
marcin
This post is intended to be a guide for others, I was running a remote debugger for the first time and appreciate feedback on how I could...
New
anuragg
We finally have a Mix clustering guide to go with Phoenix deployment with Mix Releases. Deploy an Elixir Cluster with Mix Releases and l...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement