shahryarjb

shahryarjb

How do I fix the unused variable's error which I used?

In my controller, I improved and prevent dirty code in my project, for example, I was trying to put my params in variable like this:

Original codes :

def create_cms_post(conn, %{ 
      "title" => title, 
      "status" => status, 
      "post_type" => post_type, 
      "download_ext_link" => download_ext_link, 
      "price" => price, 
      "pic_x1_link" => pic_x1_link, 
      "pic_x2_link" => pic_x2_link, 
      "pic_x3_link" => pic_x3_link, 
      "group_acl" => group_acl, 
      "description" => description, 
      "changelog" => changelog, 
      "changelog_category" => changelog_category, 
      "plugin" => plugin, 
      "plugin_category" => plugin_category, 
      ....
      ....
      ....
    }) do

      create_cms_posts = case PostQuery.insert_post(title, status, post_type, **.... and more ...**) do

when I have done it my code was clear.

Edited codes :

def create_cms_post(conn, %{ 
      "title" => title, 
      "status" => status, 
      "post_type" => post_type, 
      "download_ext_link" => download_ext_link, 
      "price" => price, 
      "pic_x1_link" => pic_x1_link, 
      "pic_x2_link" => pic_x2_link, 
      ....
      ....
      ....
    } = allreq) do
      create_cms_posts = case PostQuery.insert_post(allreq) do

I have put params in one variable and I was putting in my function which I needed.

Now my codes works for me without any problems. but I have many the unused errors when I’m compiling my project.

  1. first question, does the errors have a bad efect on me ?
  2. and second , how can I fix this not to show me?

Thanks.

Marked As Solved

NobbZ

NobbZ

They are warnings, if they were errors they had the bad effect of failing the compilation.

Unused variable warnings are emitted during compiletime and should be a hint to you as the developer, that you might have forgotten to actually process a value that you have bound to a name. Thats the main reason for the warning.

It does not affect runtime behaviour off your application (well, maybe stack size is increased because of that, but I am not 100% sure on this as we have a lot of optimizer passes in between).

  1. Use the variables you bound
  2. Prefix the variables with an understcore (eg. _example) while binding
  3. Do not bind at all.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
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 Postgres...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement