Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A federal ban on the sale of guns to holders of medical marijuana cards doesn't violate the Second Amendment, a federal appeals court said Wednesday.

The ruling by the 9th U.S. Circuit Court of Appeals in San Francisco came in a lawsuit filed by S. Rowan Wilson, a Nevada woman who said she tried to buy a firearm for self-defense in 2011 after having obtained a medical marijuana card. The gun store refused, citing the federal rule banning the sale of firearms to illegal drug users.

Marijuana remains illegal under federal law, and the federal Bureau of Alcohol, Tobacco, Firearms and Explosives has told gun sellers they can assume that a person with a medical marijuana card uses the drug.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: Do Medical Marijuana Users Have Right to Bear Arms? No, Says ATF

The 9th Circuit said in its 3-0 decision that Congress reasonably concluded that marijuana and other drug use "raises the risk of irrational or unpredictable behavior with which gun use should not be associated."

A medical marijuana dispensary in New York in January. Shannon Stapleton / Reuters

Wilson's attorney, Chaz Rainey, said there needs to be more consistency in applying the Second Amendment. He planned to appeal.

"We live in a world where having a medical marijuana card is enough to say you don't get a gun, but if you're on the no-fly list, your constitutional right is still protected," he said.

Paul Armentano, deputy director of the National Organization for the Reform of Marijuana Laws, said the idea that marijuana users were more prone to violence is a fallacy.

"Responsible adults who use cannabis in a manner that is compliant with the laws of their states ought to receive the same legal rights and protections as other citizens," he said.

The ruling applies only in the nine Western states that fall under the court's jurisdiction, including California, Washington and Oregon.