Even after cities try and regulate dispensaries as best as possible, the federal government steps in and creates more havoc for the cities.

The panel rules that the city authorized distribution of pot in violation of federal law. The decision could force Los Angeles to rewrite its medical marijuana ordinance.

In a decision that could upend the way California cities regulate medical marijuana, a state Court of Appeal has ruled that Long Beach's ordinance regulating dispensaries violates federal law.

The city held a lottery, issued permits to the winners and charged fees, which the three-judge panel said put it in the position of authorizing the distribution of marijuana in direct conflict with the federal Controlled Substances Act, which makes the possession and sale of the drug illegal. Marijuana use remains illegal under California law except for medical purposes.

The ruling, which was filed Tuesday, could require Long Beach and other cities, including Los Angeles, to rewrite their medical marijuana ordinances, a process that has been fraught with delay and chaos. Many cities that have long allowed dispensaries, such as San Francisco and Oakland, have permit-based ordinances that let officials decide who can sell the drug. Then they charge high fees and closely regulate them.